﻿#include "printreport.h"
#include<QtPrintSupport/QPrinter>
#include<QPainter>
#include<QString>
#include<Report/smoothcurvegenerator.h>
#include<Beans/databeans.h>
#include<math.h>
#include "HRVPro/hrvdataprocess.h"
#include "QSettings"
#include "QDir"
#include "Config/constant.h"
PrintReport::PrintReport()
{

}

PrintReport::~PrintReport()
{

}

void PrintReport::Report_Surgest(DataBeans dataBean){
        QString PatientID=dataBean.UserName;
        QString Age=dataBean.UserAge;
        QString Gender=dataBean.UserSex;

        QString MeasureTime=dataBean.MeasureTime;
        HRVDataProcess hrvdataPro;
        HRVIndex hi=hrvdataPro.Json2HRVData(dataBean.hrvIndexResults);
        QPrinter printer;
        printer.setPageSize(QPageSize::A4);
//        double x=double(printer.pageRect().width())/761;
//        double y=double(printer.pageRect().height())/1091;
//        printer.setOutputFormat(QPrinter::PdfFormat);
//        printer.setOutputFileName("C:\\Users\\whb\\Desktop\\report_Ans.pdf");
        QPainter painter(&printer);
        painter.setRenderHint(QPainter::Antialiasing);
        //定义几种画笔
        QPen pen_White,pen_Yello,Pen_Gray,Pen_Black;
        pen_White.setWidth(1);
        pen_Yello.setWidth(1);
        Pen_Gray.setWidth(1);
        Pen_Black.setWidth(1);
        pen_White.setColor(QColor(255,255,255));
        pen_Yello.setColor(QColor(255,128,0));
        Pen_Gray.setColor(QColor(220,220,220));
        Pen_Black.setColor(QColor(0,0,0));
        painter.setPen(pen_White);
        //定义几种字体
        QFont font1("隶书",15,false);
        QFont font2("隶书",12,false);
        QFont font3("宋体",12,false);
        QFont font4("宋体",10,false);
        QFont font5("宋体",8,false);
        painter.setFont(font1);
        //--------------------------------------------绘制标题边框-------------------------------------------

        QRect rect_TitleBackGround(QPoint(0,0),QPoint(761,150));
        painter.setBrush(QBrush(QColor(255,128,0),Qt::SolidPattern));
        painter.drawRect(rect_TitleBackGround);
        QRect rect_Title(QPoint(220,50),QPoint(761,100));
        painter.drawText(rect_Title,"心理压力/心脏自主神经功能检测报告");
        painter.drawLine(QPoint(200,80),QPoint(570,80));

        //--------------------------------------------绘制测试信息-------------------------------------------
        painter.setFont(font2);
        painter.drawText(QRect(60,120,110,140),"姓名");
        painter.drawText(QRect(220,120,250,140),"性别");
        painter.drawText(QRect(360,120,390,140),"年龄");
        painter.drawText(QRect(480,120,540,140),"监测时间");

        painter.drawLine(QPoint(90,145),QPoint(210,145));
        painter.drawLine(QPoint(250,145),QPoint(350,145));
        painter.drawLine(QPoint(390,145),QPoint(480,145));
        painter.drawLine(QPoint(540,145),QPoint(730,145));

        painter.setFont(font3);
        painter.drawText(QRect(90+30,120,220,120),PatientID);
        painter.drawText(QRect(250+40,120,360,120),Gender);
        painter.drawText(QRect(390+40,120,480,120),Age);
        painter.drawText(QRect(540+20,120,761,120),MeasureTime);


        //绘制心理压力分析
        painter.setBrush(QBrush(QColor(220,220,220),Qt::SolidPattern));
        painter.drawRect(QRect(QPoint(0,155),QPoint(761,180)));
        painter.setPen(pen_Yello);
        painter.setFont(font2);
        painter.drawText(QRect(10,160,280,180),"△心理压力分析");
        painter.setPen(Pen_Gray);
        for(int i=0;i<8;i++){
            painter.drawLine(0,180+30*i,761,180+30*i);
        }
        for(int i=0;i<3;i++){
            painter.drawLine(161+200*i,180,161+200*i,390);
        }
        painter.setPen(Pen_Black);

        painter.drawText(QRect(30,215,161,240),"身体抗压能力");
        painter.drawText(QRect(257,185,280,210),"差");
        painter.drawText(QRect(443,185,521,210),"正常");
        painter.drawText(QRect(641,185,761,210),"强");

        painter.drawText(QRect(30,275,161,300),"精神压力状态");
        painter.drawText(QRect(257,185+60,280,210+60),"小");
        painter.drawText(QRect(443,185+60,521,210+60),"正常");
        painter.drawText(QRect(641,185+60,641,210+60),"大");

        painter.drawText(QRect(30,305,161,330),"精神疲劳状态");
        painter.drawText(QRect(252,185+150,280,210+150),"消极");
        painter.drawText(QRect(443,185+150,521,210+150),"正常");
        painter.drawText(QRect(635,185+150,641,210+150),"焦虑");

        painter.drawText(QRect(30,365,161,390),"精神情绪状态");

        painter.setPen(pen_Yello);
        double rpai=hi.mp.SdnnScore;
        double mpi=hi.mp.MsiScore;
        double mfi=hi.mp.PsiScore;
        double ems=hi.mp.EmotionScore;
        painter.setBrush(QBrush(QColor(255,128,0),Qt::SolidPattern));
        painter.drawRect(QRect(QPoint(161,220),QPoint(161+rpai*6,230)));
        painter.drawRect(QRect(QPoint(161,280),QPoint(161+mpi*6,290)));
        painter.drawRect(QRect(QPoint(161,310),QPoint(161+mfi*6,320)));
        painter.drawRect(QRect(QPoint(161,370),QPoint(161+ems*60,380)));


        //HRV
        painter.setPen(Pen_Gray);
        painter.setBrush(QBrush(QColor(220,220,220),Qt::SolidPattern));
        painter.drawRect(QRect(QPoint(0,400),QPoint(761,425)));
        painter.setPen(pen_Yello);
        painter.setFont(font2);
        painter.drawText(QRect(10,405,280,425),"△HRV");
        painter.setPen(Pen_Black);
        painter.setFont(font5);
        for(int i=0;i<5;i++){
            painter.drawLine(80,435+30*i,83,435+30*i);
            if(i<2){
               painter.drawText(QRect(55,430+30*i,80,430+30*i),QString::number(1200-i*200));
            }else{
                painter.drawText(QRect(60,430+30*i,80,430+30*i),QString::number(1200-i*200));
            }
        }

        painter.setPen(Pen_Gray);
        painter.drawLine(83,435,83,558);
        painter.drawLine(83,435,761,435);
        painter.drawLine(83,555,761,555);
        painter.drawLine(761,435,761,555);
        painter.setPen(Pen_Black);
        painter.setFont(font4);
        painter.drawText(QRect(35,485,280,485), "ms");
        painter.setPen(pen_Yello);
        QList<int>RR=hi.time.RR;
        QList<QPointF> points1; // 曲线一的顶点数组
        QPainterPath smoothCurvePath1; // 平滑曲线一
        // 生成曲线的坐标
        double x1=83.0;
        double y1=0.0;
        for (int i = 0; i < RR.size(); i++) {
            x1 += 678.0 / RR.size();
            y1 = -120*(RR.at(i)-1200)/800+435;
            points1 << QPointF(x1, y1);
        }
        // 使用曲线的坐标生成平滑曲线
        smoothCurvePath1 = SmoothCurveGenerator::generateSmoothCurve(points1); // 不封闭
        // 绘制平滑曲线和曲线上的顶点
        painter.setRenderHint(QPainter::Antialiasing);
        painter.setBrush(QBrush(QColor(255,255,255),Qt::SolidPattern));
        painter.setPen(QPen(QColor(255,128,0), 1));
        painter.drawPath(smoothCurvePath1);
//        painter.setBrush(Qt::gray);
        for (int i = 0; i < points1.length() ; i += 1) {
            painter.drawEllipse(points1[i].x()-1, points1[i].y()-1, 2, 2);
        }

        //绘制自主神经系统平衡图

        painter.setPen(Pen_Gray);
        painter.setBrush(QBrush(QColor(220,220,220),Qt::SolidPattern));
        painter.drawRect(QRect(QPoint(0,580),QPoint(761,605)));
        painter.setPen(pen_Yello);
        painter.setFont(font2);
        painter.drawText(QRect(10,585,280,605),"△自主神经系统平衡图");


        QPoint CenterPoint=QPoint(180,700);//中心坐标
        int r1=80;
        int r2=60;
        int r3=30;
        int r4=5;
        painter.setFont(font2);
        painter.setPen(Pen_Gray);
        // 坐标轴的四个点
        QPoint leftdown=QPoint(CenterPoint.x()-(r1+10),CenterPoint.y()+(r1+10));
        QPoint leftup=QPoint(CenterPoint.x()-(r1+10),CenterPoint.y()-(r1+10));
        QPoint rightdown=QPoint(CenterPoint.x()+(r1+10),CenterPoint.y()+(r1+10));
        QPoint rightup=QPoint(CenterPoint.x()+(r1+10),CenterPoint.y()-(r1+10));
        painter.drawLine(leftdown,leftup);
        painter.drawLine(leftdown,rightdown);
        painter.drawLine(leftup,rightup);
        painter.drawLine(rightup,rightdown);

        QPen pen_Ellipse;
        pen_Ellipse.setColor(QColor(230,243,255));
        painter.setBrush(QBrush(QColor(230,243,255),Qt::SolidPattern)); //设置画刷形式
        painter.setPen(pen_Ellipse);
        painter.drawEllipse(CenterPoint,r1,r1);

        pen_Ellipse.setColor(QColor(214,234,253));
        painter.setBrush(QBrush(QColor(214,234,253),Qt::SolidPattern)); //设置画刷形式
        painter.setPen(pen_Ellipse);
        painter.drawEllipse(CenterPoint,r2,r2);

        pen_Ellipse.setColor(QColor(181,212,243));
        painter.setBrush(QBrush(QColor(181,212,243),Qt::SolidPattern)); //设置画刷形式
        painter.setPen(pen_Ellipse);
        painter.drawEllipse(CenterPoint,r3,r3);

        pen_Ellipse.setColor(QColor(100,180,232));
        painter.setBrush(QBrush(QColor(100,180,232),Qt::SolidPattern)); //设置画刷形式
        painter.setPen(pen_Ellipse);
        painter.drawEllipse(CenterPoint,r4,r4);

        painter.setPen(Pen_Black);
        painter.drawText(QRect(CenterPoint.x()-15,CenterPoint.y()+(r1+20),200,CenterPoint.y()+(r1+40)),"低频");
        painter.drawText(QRect(CenterPoint.x()-(r1+30),CenterPoint.y()-20,100,CenterPoint.y()),"高");
        painter.drawText(QRect(CenterPoint.x()-(r1+30),CenterPoint.y(),100,CenterPoint.y()+20),"频");

        //假定LF的正常范围
        int x_LF=hi.freq.LFnorm*180/100+90;
        int y_HF=790-180*hi.freq.HFnorm/100;
        pen_Ellipse.setColor(QColor(255,0,0));
        painter.setPen(pen_Ellipse);
        painter.setBrush(QBrush(QColor(255,0,0),Qt::SolidPattern)); //设置画刷形式
        painter.drawEllipse(x_LF-5, y_HF-5, 10, 10);


        //绘制自主神经柱状图
        painter.setPen(Pen_Gray);
        painter.setFont(font5);
        for(int i=0;i<6;i++){
            painter.drawLine(420,630+i*30,423,630+i*30);
            painter.drawLine(425,630+i*30,700,630+i*30);
        }
        painter.setPen(Pen_Black);
        for(int i=0;i<6;i++){
            if(i<1){
                painter.drawText(QRect(395,625+30*i,20,20),QString::number(100-i*20));
            }else if(i<5){
                painter.drawText(QRect(400,625+30*i,20,20),QString::number(100-i*20));
            }else{
                painter.drawText(QRect(405,625+30*i,20,20),QString::number(100-i*20));
            }
        }
        painter.setFont(font2);
        painter.drawText(QRect(505,800,50,20),"交感");
        painter.drawText(QRect(581,800,50,20),"副交感");

        painter.setPen(pen_Yello);
        painter.setBrush(QBrush(QColor(255,128,0),Qt::SolidPattern));
        painter.drawRect(QRect(QPoint(530,780),QPoint(510,780-1.5*hi.freq.LFnorm)));
        painter.drawRect(QRect(QPoint(611,780),QPoint(591,780-1.5*hi.freq.HFnorm)));

        //绘制诊断结论及注意事项

        painter.setPen(Pen_Gray);
        painter.setBrush(QBrush(QColor(220,220,220),Qt::SolidPattern));
        painter.drawRect(QRect(QPoint(0,825),QPoint(761,850)));
        painter.setPen(pen_Yello);
        painter.setFont(font2);
        painter.drawText(QRect(10,830,200,50),"△诊断结论及注意事项");

        painter.setPen(Pen_Gray);
        painter.setBrush(QBrush(QColor(255,255,255),Qt::SolidPattern));
        painter.drawRect(QRect(0,860,761,180));
        painter.setPen(Pen_Black);
        painter.setFont(font4);

        painter.drawText(QRect(3,863,761,180),hi.MentalPressureResults+"\n"+hi.AnsResults);
        painter.drawText(QRect(500,1065,300,20),"本报告仅供参考，不作为医疗依据");




}
void PrintReport::Report_Surgest_five(DataBeans dataBean){
        QString PatientID=dataBean.UserName;
        QString Age=dataBean.UserAge;
        QString Gender=dataBean.UserSex;

        QString MeasureTime=dataBean.MeasureTime;
        HRVDataProcess hrvdataPro;
        HRVIndex hi=hrvdataPro.Json2HRVData(dataBean.hrvIndexResults);
        QPrinter printer;
        printer.setPageSize(QPageSize::A4);
//        double x=double(printer.pageRect().width())/761;
//        double y=double(printer.pageRect().height())/1091;
        printer.setOutputFormat(QPrinter::PdfFormat);
        printer.setOutputFileName("C:\\Users\\whb\\Desktop\\report_Ans.pdf");
        QPainter painter(&printer);
        painter.setRenderHint(QPainter::Antialiasing);
        //定义几种画笔
        QPen pen_White,pen_Yello,Pen_Gray,Pen_Black;
        pen_White.setWidth(1);
        pen_Yello.setWidth(1);
        Pen_Gray.setWidth(1);
        Pen_Black.setWidth(1);
        pen_White.setColor(QColor(255,255,255));
        pen_Yello.setColor(QColor(255,128,0));
        Pen_Gray.setColor(QColor(220,220,220));
        Pen_Black.setColor(QColor(0,0,0));
        painter.setPen(pen_White);
        //定义几种字体
        QFont font1("隶书",15,false);
        QFont font2("隶书",12,false);
        QFont font3("宋体",12,false);
        QFont font4("宋体",10,false);
        QFont font5("宋体",8,false);
        painter.setFont(font1);
        //--------------------------------------------绘制标题边框-------------------------------------------

        QRect rect_TitleBackGround(QPoint(0,0),QPoint(761,150));
        painter.setBrush(QBrush(QColor(255,128,0),Qt::SolidPattern));
        painter.drawRect(rect_TitleBackGround);
        QRect rect_Title(QPoint(220,50),QPoint(761,100));
        painter.drawText(rect_Title,"心理压力/心脏自主神经功能检测报告");
        painter.drawLine(QPoint(200,80),QPoint(570,80));

        //--------------------------------------------绘制测试信息-------------------------------------------
        painter.setFont(font2);
        painter.drawText(QRect(60,120,110,140),"姓名");
        painter.drawText(QRect(220,120,250,140),"性别");
        painter.drawText(QRect(360,120,390,140),"年龄");
        painter.drawText(QRect(480,120,540,140),"监测时间");

        painter.drawLine(QPoint(90,145),QPoint(210,145));
        painter.drawLine(QPoint(250,145),QPoint(350,145));
        painter.drawLine(QPoint(390,145),QPoint(480,145));
        painter.drawLine(QPoint(540,145),QPoint(730,145));

        painter.setFont(font3);
        painter.drawText(QRect(90+30,120,220,120),PatientID);
        painter.drawText(QRect(250+40,120,360,120),Gender);
        painter.drawText(QRect(390+40,120,480,120),Age);
        painter.drawText(QRect(540+20,120,761,120),MeasureTime);


        //绘制心理压力分析
        painter.setBrush(QBrush(QColor(220,220,220),Qt::SolidPattern));
        painter.drawRect(QRect(QPoint(0,155),QPoint(761,180)));
        painter.setPen(pen_Yello);
        painter.setFont(font2);
        painter.drawText(QRect(10,160,280,180),"△心理压力分析");
        painter.setPen(Pen_Gray);
        for(int i=0;i<8;i++){
            painter.drawLine(0,180+30*i,761,180+30*i);
        }
        for(int i=0;i<5;i++){
            painter.drawLine(161+120*i,180,161+120*i,390);
        }
        painter.setPen(Pen_Black);

        painter.drawText(QRect(30,215,161,240),"身体抗压能力");
        painter.drawText(QRect(203,185,280,210),"极差");
        painter.drawText(QRect(331,185,401,210),"差");
        painter.drawText(QRect(443,185,521,210),"正常");
        painter.drawText(QRect(571,185,641,210),"好");
        painter.drawText(QRect(691,185,761,210),"优");

        painter.drawText(QRect(30,275,161,300),"精神压力状态");
        painter.drawText(QRect(211,185+60,280,210+60),"优");
        painter.drawText(QRect(331,185+60,401,210+60),"好");
        painter.drawText(QRect(443,185+60,521,210+60),"正常");
        painter.drawText(QRect(571,185+60,641,210+60),"差");
        painter.drawText(QRect(683,185+60,761,210+60),"极差");

        painter.drawText(QRect(30,305,161,330),"精神疲劳状态");
        painter.drawText(QRect(211,185+150,280,210+150),"差");
        painter.drawText(QRect(331,185+150,401,210+150),"好");
        painter.drawText(QRect(451,185+150,521,210+150),"优");
        painter.drawText(QRect(571,185+150,641,210+150),"好");
        painter.drawText(QRect(691,185+150,761,210+150),"差");

        painter.drawText(QRect(30,365,161,390),"精神情绪状态");

        painter.setPen(pen_Yello);
        double rpai=hi.mp.SdnnScore;
        double mpi=hi.mp.MsiScore;
        double mfi=hi.mp.PsiScore;
        double ems=hi.mp.EmotionScore;
        painter.setBrush(QBrush(QColor(255,128,0),Qt::SolidPattern));
        painter.drawRect(QRect(QPoint(161,220),QPoint(161+rpai*6,230)));
        painter.drawRect(QRect(QPoint(161,280),QPoint(161+mpi*6,290)));
        painter.drawRect(QRect(QPoint(161,310),QPoint(161+mfi*6,320)));
        painter.drawRect(QRect(QPoint(161,370),QPoint(161+ems*60,380)));


        //HRV
        painter.setPen(Pen_Gray);
        painter.setBrush(QBrush(QColor(220,220,220),Qt::SolidPattern));
        painter.drawRect(QRect(QPoint(0,400),QPoint(761,425)));
        painter.setPen(pen_Yello);
        painter.setFont(font2);
        painter.drawText(QRect(10,405,280,425),"△HRV");
        painter.setPen(Pen_Black);
        painter.setFont(font5);
        for(int i=0;i<5;i++){
            painter.drawLine(80,435+30*i,83,435+30*i);
            if(i<2){
               painter.drawText(QRect(55,430+30*i,80,430+30*i),QString::number(1200-i*200));
            }else{
                painter.drawText(QRect(60,430+30*i,80,430+30*i),QString::number(1200-i*200));
            }
        }

        painter.setPen(Pen_Gray);
        painter.drawLine(83,435,83,558);
        painter.drawLine(83,435,761,435);
        painter.drawLine(83,555,761,555);
        painter.drawLine(761,435,761,555);
        painter.setPen(Pen_Black);
        painter.setFont(font4);
        painter.drawText(QRect(35,485,280,485), "ms");
        painter.setPen(pen_Yello);
        QList<int>RR=hi.time.RR;
        QList<QPointF> points1; // 曲线一的顶点数组
        QPainterPath smoothCurvePath1; // 平滑曲线一
        // 生成曲线的坐标
        double x1=83.0;
        double y1=0.0;
        for (int i = 0; i < RR.size(); i++) {
            x1 += 678.0 / RR.size();
            y1 = -120*(RR.at(i)-1200)/800+435;
            points1 << QPointF(x1, y1);
        }
        // 使用曲线的坐标生成平滑曲线
        smoothCurvePath1 = SmoothCurveGenerator::generateSmoothCurve(points1); // 不封闭
        // 绘制平滑曲线和曲线上的顶点
        painter.setRenderHint(QPainter::Antialiasing);
        painter.setBrush(QBrush(QColor(255,255,255),Qt::SolidPattern));
        painter.setPen(QPen(QColor(255,128,0), 1));
        painter.drawPath(smoothCurvePath1);
//        painter.setBrush(Qt::gray);
        for (int i = 0; i < points1.length() ; i += 1) {
            painter.drawEllipse(points1[i].x()-1, points1[i].y()-1, 2, 2);
        }

        //绘制自主神经系统平衡图

        painter.setPen(Pen_Gray);
        painter.setBrush(QBrush(QColor(220,220,220),Qt::SolidPattern));
        painter.drawRect(QRect(QPoint(0,580),QPoint(761,605)));
        painter.setPen(pen_Yello);
        painter.setFont(font2);
        painter.drawText(QRect(10,585,280,605),"△自主神经系统平衡图");


        QPoint CenterPoint=QPoint(180,700);//中心坐标
        int r1=80;
        int r2=60;
        int r3=30;
        int r4=5;
        painter.setFont(font2);
        painter.setPen(Pen_Gray);
        // 坐标轴的四个点
        QPoint leftdown=QPoint(CenterPoint.x()-(r1+10),CenterPoint.y()+(r1+10));
        QPoint leftup=QPoint(CenterPoint.x()-(r1+10),CenterPoint.y()-(r1+10));
        QPoint rightdown=QPoint(CenterPoint.x()+(r1+10),CenterPoint.y()+(r1+10));
        QPoint rightup=QPoint(CenterPoint.x()+(r1+10),CenterPoint.y()-(r1+10));
        painter.drawLine(leftdown,leftup);
        painter.drawLine(leftdown,rightdown);
        painter.drawLine(leftup,rightup);
        painter.drawLine(rightup,rightdown);

        QPen pen_Ellipse;
        pen_Ellipse.setColor(QColor(230,243,255));
        painter.setBrush(QBrush(QColor(230,243,255),Qt::SolidPattern)); //设置画刷形式
        painter.setPen(pen_Ellipse);
        painter.drawEllipse(CenterPoint,r1,r1);

        pen_Ellipse.setColor(QColor(214,234,253));
        painter.setBrush(QBrush(QColor(214,234,253),Qt::SolidPattern)); //设置画刷形式
        painter.setPen(pen_Ellipse);
        painter.drawEllipse(CenterPoint,r2,r2);

        pen_Ellipse.setColor(QColor(181,212,243));
        painter.setBrush(QBrush(QColor(181,212,243),Qt::SolidPattern)); //设置画刷形式
        painter.setPen(pen_Ellipse);
        painter.drawEllipse(CenterPoint,r3,r3);

        pen_Ellipse.setColor(QColor(100,180,232));
        painter.setBrush(QBrush(QColor(100,180,232),Qt::SolidPattern)); //设置画刷形式
        painter.setPen(pen_Ellipse);
        painter.drawEllipse(CenterPoint,r4,r4);

        painter.setPen(Pen_Black);
        painter.drawText(QRect(CenterPoint.x()-15,CenterPoint.y()+(r1+20),200,CenterPoint.y()+(r1+40)),"低频");
        painter.drawText(QRect(CenterPoint.x()-(r1+30),CenterPoint.y()-20,100,CenterPoint.y()),"高");
        painter.drawText(QRect(CenterPoint.x()-(r1+30),CenterPoint.y(),100,CenterPoint.y()+20),"频");

        //假定LF的正常范围
        int x_LF=hi.freq.LFnorm*180/100+90;
        int y_HF=790-180*hi.freq.HFnorm/100;
        pen_Ellipse.setColor(QColor(255,0,0));
        painter.setPen(pen_Ellipse);
        painter.setBrush(QBrush(QColor(255,0,0),Qt::SolidPattern)); //设置画刷形式
        painter.drawEllipse(x_LF-5, y_HF-5, 10, 10);


        //绘制自主神经柱状图
        painter.setPen(Pen_Gray);
        painter.setFont(font5);
        for(int i=0;i<6;i++){
            painter.drawLine(420,630+i*30,423,630+i*30);
            painter.drawLine(425,630+i*30,700,630+i*30);
        }
        painter.setPen(Pen_Black);
        for(int i=0;i<6;i++){
            if(i<1){
                painter.drawText(QRect(395,625+30*i,20,20),QString::number(100-i*20));
            }else if(i<5){
                painter.drawText(QRect(400,625+30*i,20,20),QString::number(100-i*20));
            }else{
                painter.drawText(QRect(405,625+30*i,20,20),QString::number(100-i*20));
            }
        }
        painter.setFont(font2);
        painter.drawText(QRect(505,800,50,20),"交感");
        painter.drawText(QRect(581,800,50,20),"副交感");

        painter.setPen(pen_Yello);
        painter.setBrush(QBrush(QColor(255,128,0),Qt::SolidPattern));
        painter.drawRect(QRect(QPoint(530,780),QPoint(510,780-1.5*hi.freq.LFnorm)));
        painter.drawRect(QRect(QPoint(611,780),QPoint(591,780-1.5*hi.freq.HFnorm)));

        //绘制诊断结论及注意事项

        painter.setPen(Pen_Gray);
        painter.setBrush(QBrush(QColor(220,220,220),Qt::SolidPattern));
        painter.drawRect(QRect(QPoint(0,825),QPoint(761,850)));
        painter.setPen(pen_Yello);
        painter.setFont(font2);
        painter.drawText(QRect(10,830,200,50),"△诊断结论及注意事项");

        painter.setPen(Pen_Gray);
        painter.setBrush(QBrush(QColor(255,255,255),Qt::SolidPattern));
        painter.drawRect(QRect(0,860,761,180));
        painter.setPen(Pen_Black);
        painter.setFont(font4);

        painter.drawText(QRect(3,863,761,180),hi.MentalPressureResults+"\n"+hi.AnsResults);
        painter.drawText(QRect(500,1065,300,20),"本报告仅供参考，不作为医疗依据");




}

void PrintReport::Report_Explain(DataBeans dataBean){
    QString PatientID=dataBean.UserName;
    QString Age=dataBean.UserAge;
    QString Gender=dataBean.UserSex;

    QString MeasureTime=dataBean.MeasureTime;

    QPrinter printer;
    printer.setPageSize(QPageSize::A4);
    printer.setOutputFormat(QPrinter::PdfFormat);
    printer.setOutputFileName("D:\\report_Expain.pdf");

    QPainter painter(&printer);
    painter.setRenderHint(QPainter::Antialiasing);
    //定义几种画笔
    QPen pen_White,pen_Yello,Pen_Gray,Pen_Black;
    pen_White.setWidth(1);
    pen_Yello.setWidth(1);
    Pen_Gray.setWidth(1);
    Pen_Black.setWidth(1);
    pen_White.setColor(QColor(255,255,255));
    pen_Yello.setColor(QColor(255,128,0));
    Pen_Gray.setColor(QColor(220,220,220));
    Pen_Black.setColor(QColor(0,0,0));
    painter.setPen(pen_White);
    //定义几种字体
    QFont font1("隶书",20,false);
    QFont font2("隶书",12,false);
    QFont font3("宋体",12,false);
    QFont font4("宋体",10,false);
    QFont font5("宋体",8,false);
    painter.setFont(font1);
    //--------------------------------------------绘制标题边框-------------------------------------------

    QRect rect_TitleBackGround(QPoint(0,0),QPoint(761,150));
    painter.setBrush(QBrush(QColor(255,128,0),Qt::SolidPattern));
    painter.drawRect(rect_TitleBackGround);
    QRect rect_Title(QPoint(220,50),QPoint(761,100));
    painter.drawText(rect_Title,"      科  普  报  告");
    painter.drawLine(QPoint(200,80),QPoint(590,80));

    //--------------------------------------------绘制测试信息-------------------------------------------
    painter.setFont(font2);
    painter.drawText(QRect(60,120,110,140),"姓名");
    painter.drawText(QRect(220,120,250,140),"性别");
    painter.drawText(QRect(360,120,390,140),"年龄");
    painter.drawText(QRect(480,120,540,140),"监测时间");

    painter.drawLine(QPoint(90,145),QPoint(210,145));
    painter.drawLine(QPoint(250,145),QPoint(350,145));
    painter.drawLine(QPoint(390,145),QPoint(480,145));
    painter.drawLine(QPoint(540,145),QPoint(730,145));

    painter.setFont(font3);
    painter.drawText(QRect(90+30,120,220,120),PatientID);
    painter.drawText(QRect(250+40,120,360,120),Gender);
    painter.drawText(QRect(390+40,120,480,120),Age);
    painter.drawText(QRect(540+20,120,761,120),MeasureTime);
    //一、如何缓解心理压力
    painter.setBrush(QBrush(QColor(220,220,220),Qt::SolidPattern));
    painter.drawRect(QRect(QPoint(0,155),QPoint(761,180)));
    painter.setPen(pen_Yello);
    QFont font("隶书",12,true);
    painter.setFont(font);
    painter.drawText(QRect(10,160,200,25),"一、如何缓解心理压力");
    painter.setPen(Pen_Gray);
    painter.setBrush(QBrush(QColor(255,255,255),Qt::SolidPattern));
    painter.drawRect(QRect(0,185,761,260));
    painter.setPen(Pen_Black);
    painter.setFont(font3);
    painter.setBrush(QBrush(QColor(220,220,220),Qt::SolidPattern));
    painter.drawText(QRect(3,188,761,260),"1、充足的睡眠\n在发生心理压力大的时候我们可以用睡眠的方式来进行有效的缓解，因为睡眠不足会导致严重后果，不仅影响我们的身体健康，还能造成全天焦虑和紧张。有时还会形成恶性循环，焦虑通常会阻碍睡眠。\n2、笑一笑\n经常的笑一笑也是可以有效的缓解压力的存在，当工作让我们情绪低落时，迅速调整下心态，微笑或是放松大笑。研究表明笑声能够缓解抑郁和焦虑。\n3、简化大脑\n物质简化=心理简化。如果工作的地点混乱不堪，就很难放松心情，且使工作显得更加凌乱繁琐。因此花15分钟左右整理一下房间或办公桌，并养成保持事物干净的好习惯，这些可以帮助我们更理性地思考问题。\n4、冥想\n现在我们应该都知道冥想就是放松，但科学家们同时也发现冥想实际会增加大脑内的灰质——可令体内的压力减少的物质。很多专业人士都强调了冥想对焦虑、情绪和压力症状的积极作用。 此外，冥想还是一种观察大脑的方法，让我们搞清楚耐人寻味的焦虑情绪到底是如何产生的。而理解大脑的思维模式有助于让我们远离那些负面情绪。");
    //二、如何改善睡眠
    painter.setPen(Pen_Gray);
    painter.setBrush(QBrush(QColor(220,220,220),Qt::SolidPattern));
    painter.drawRect(QRect(QPoint(0,450),QPoint(761,475)));
    painter.setPen(pen_Yello);
    painter.setFont(font);
    painter.drawText(QRect(10,455,200,25),"二、如何改善睡眠");
    painter.setPen(Pen_Gray);
    painter.setBrush(QBrush(QColor(255,255,255),Qt::SolidPattern));
    painter.drawRect(QRect(0,480,761,350));
    painter.setPen(Pen_Black);
    painter.setFont(font3);
    painter.setBrush(QBrush(QColor(220,220,220),Qt::SolidPattern));
    painter.drawText(QRect(3,483,761,350),"睡眠很重要，它不仅可以恢复身体，还可以进行重要的代谢过程，例如清除大脑中的有毒蛋白质。当然，在睡眠期间，大脑并不休息，“睡眠中”的大脑非常忙于将短期记忆整合为长期记忆。睡眠不足与多种健康问题有关，比如它会增加身体炎症发生率和降低注意力，阻碍脂肪减少，影响胰岛素信号传导，阻碍睾丸激素产生，影响心血管健康。\n1、光\n光线会影响褪黑激素来帮助调节人体生物钟，褪黑激素是一种激素，可向你发出信号，告知你该进入睡眠了。蓝光（由太阳产生，但也由电视机，计算机和智能手机的屏幕产生）会干扰褪黑激素的产生。如果受蓝光影响，即使是智能手机的小屏幕也可能使你难以入睡。因此，你在就寝之前尽量就不要看手机了。如果你生活在光污染的地区，请考虑通过安装遮光窗帘或使用睡眠眼罩来避免光对于睡眠的影响。\n2、热量\n身体体温升高与失眠正相关。因此，如果你的卧室太热，足以升高您的体温，则你可能难以入睡，并且睡眠质量可能会下降。即使高温不能阻止你入睡，你仍应选择在凉爽的房间里睡觉，因为热量对睡眠质量的影响远大于噪音。\n3、锻炼适量的运动，会促进睡眠。“睡得更好，多运动”与“多运动，睡得更好”这两个科学研究观点一直在反复争论。“睡得更好，多运动”这个已经被众多机构的研究报告证明，所以健身的朋友还是要保证7小时以上的睡眠，才能保证你的训练质量。\n4、薰衣草\n睡眠不足的许多原因中，最常见的两个原因是压力和没有足够的睡眠时间。薰衣草可以缓解压力，其香气可促进放松，减轻失眠并改善睡眠质量。");
    //三、心率变异性依据
    painter.setPen(Pen_Gray);
    painter.setBrush(QBrush(QColor(220,220,220),Qt::SolidPattern));
    painter.drawRect(QRect(QPoint(0,835),QPoint(761,860)));
    painter.setPen(pen_Yello);
    painter.setFont(font);
    painter.drawText(QRect(10,840,200,25),"三、心率变异性依据");
    painter.setPen(Pen_Gray);
    painter.setBrush(QBrush(QColor(255,255,255),Qt::SolidPattern));
    painter.drawRect(QRect(0,875,761,150));
    painter.setPen(Pen_Black);
    painter.setFont(font3);
    painter.setBrush(QBrush(QColor(220,220,220),Qt::SolidPattern));
    painter.drawText(QRect(3,878,761,150),"人体的心脏是受交感神经以及迷走神经双重支配，同时也受体液因素的影响。所以人体心率不是一个固定的数值，是处在变化的过程中的，而心率变异性的分析，实际上就是对24小时的心率，以及心动周期变异的分析，是反映神经体液对心脏支配是否平衡的一个重要指标。心率变异性明显的异常是预测恶性心律失常以及心源性猝死的独立危险因素。");

}
void PrintReport::Report_HRV(DataBeans dataBean)
{
    QString PatientID=dataBean.UserName;
    QString Age=dataBean.UserAge;
    QString Gender=dataBean.UserSex;

    QString MeasureTime=dataBean.MeasureTime;
    HRVDataProcess hrvdataPro;
    HRVIndex hi=hrvdataPro.Json2HRVData(dataBean.hrvIndexResults);
    QPrinter printer;
    printer.setPageSize(QPageSize::A4);
//    printer.setOutputFormat(QPrinter::PdfFormat);
//    printer.setOutputFileName("C:\\Users\\whb\\Desktop\\report_HRV.pdf");

    QPainter painter(&printer);
    painter.setRenderHint(QPainter::Antialiasing);
    //定义几种画笔
    QPen pen_White,pen_Yello,Pen_Gray,Pen_Black;
    pen_White.setWidth(1);
    pen_Yello.setWidth(1);
    Pen_Gray.setWidth(1);
    Pen_Black.setWidth(1);
    pen_White.setColor(QColor(255,255,255));
    pen_Yello.setColor(QColor(255,128,0));
    Pen_Gray.setColor(QColor(220,220,220));
    Pen_Black.setColor(QColor(0,0,0));
    painter.setPen(pen_White);
    //定义几种字体
    QFont font1("隶书",20,false);
    QFont font2("隶书",12,false);
    QFont font3("宋体",12,false);
    QFont font4("宋体",10,false);
    QFont font5("宋体",8,false);
    painter.setFont(font1);
    //--------------------------------------------绘制标题边框-------------------------------------------

    QRect rect_TitleBackGround(QPoint(0,0),QPoint(761,150));
    painter.setBrush(QBrush(QColor(255,128,0),Qt::SolidPattern));
    painter.drawRect(rect_TitleBackGround);
    QRect rect_Title(QPoint(220,50),QPoint(761,100));
    painter.drawText(rect_Title,"心 率 变 异 性 检 测 报 告");
    painter.drawLine(QPoint(200,80),QPoint(590,80));

    //--------------------------------------------绘制测试信息-------------------------------------------
    painter.setFont(font2);
    painter.drawText(QRect(60,120,110,140),"姓名");
    painter.drawText(QRect(220,120,250,140),"性别");
    painter.drawText(QRect(360,120,390,140),"年龄");
    painter.drawText(QRect(480,120,540,140),"监测时间");

    painter.drawLine(QPoint(90,145),QPoint(210,145));
    painter.drawLine(QPoint(250,145),QPoint(350,145));
    painter.drawLine(QPoint(390,145),QPoint(480,145));
    painter.drawLine(QPoint(540,145),QPoint(730,145));

    painter.setFont(font3);
    painter.drawText(QRect(90+30,120,220,120),PatientID);
    painter.drawText(QRect(250+40,120,360,120),Gender);
    painter.drawText(QRect(390+40,120,480,120),Age);
    painter.drawText(QRect(540+20,120,761,120),MeasureTime);
    //时域分析
    painter.setBrush(QBrush(QColor(220,220,220),Qt::SolidPattern));
    painter.drawRect(QRect(QPoint(0,155),QPoint(761,180)));
    painter.setPen(pen_Yello);
    painter.setFont(font2);
    painter.drawText(QRect(10,160,150,25),"△时域分析");

    painter.setPen(Pen_Black);
    painter.drawText(QRect(80,190,100,20),"RR间期直方图");
    painter.drawText(QRect(320,190,150,20),"RR间期差值直方图");
    painter.drawText(QRect(540,190,180,20),"RR间期差值绝对值直方图");

    painter.setPen(Pen_Gray);
    int H1_x=20;
    int H1_y=210;
    int width=220;
    int Height=100;

    painter.drawLine(QPoint(H1_x,H1_y),QPoint(H1_x+width,H1_y));
    painter.drawLine(QPoint(H1_x,H1_y),QPoint(H1_x,H1_y+Height));
    painter.drawLine(QPoint(H1_x+width,H1_y),QPoint(H1_x+width,H1_y+Height));
    painter.drawLine(QPoint(H1_x,H1_y+Height),QPoint(H1_x+width,H1_y+Height));

    int H2_x=270;
    int H2_y=210;
    painter.drawLine(QPoint(H2_x,H2_y),QPoint(H2_x+width,H2_y));
    painter.drawLine(QPoint(H2_x,H2_y),QPoint(H2_x,H2_y+Height));
    painter.drawLine(QPoint(H2_x+width,H2_y),QPoint(H2_x+width,H2_y+Height));
    painter.drawLine(QPoint(H2_x,H2_y+Height),QPoint(H2_x+width,H2_y+Height));

    int H3_x=520;
    int H3_y=210;
    painter.drawLine(QPoint(H3_x,H3_y),QPoint(H3_x+width,H3_y));
    painter.drawLine(QPoint(H3_x,H3_y),QPoint(H3_x,H3_y+Height));
    painter.drawLine(QPoint(H3_x+width,H3_y),QPoint(H3_x+width,H3_y+Height));
    painter.drawLine(QPoint(H3_x,H3_y+Height),QPoint(H3_x+width,H3_y+Height));
    painter.setPen(Pen_Black);
    painter.setFont(font5);
    for(int i=0;i<5;i++){
        painter.drawLine(H1_x+i*55,H1_y+Height,H1_x+i*55,H1_y+Height+3);
        painter.drawText(QRect(H1_x+i*55-12,H1_y+Height+3,50,20),QString::number(400+i*200));
    }
    for(int i=0;i<4;i++){
        painter.drawLine(H2_x+i*73,H2_y+Height,H2_x+i*73,H2_y+Height+3);
        painter.drawText(QRect(H2_x+i*73-8,H2_y+Height+3,50,20),QString::number(-200+i*200));
    }
    for(int i=0;i<7;i++){
        painter.drawLine(H3_x+i*36.6,H3_y+Height,H3_x+i*36.6,H3_y+Height+3);
        painter.drawText(QRect(H3_x+i*36.6-8,H3_y+Height+3,50,20),QString::number(i*50));
    }
    painter.drawText(QRect(120,H1_y+Height+13,50,20),"ms");
    painter.drawText(QRect(370,H1_y+Height+13,50,20),"ms");
    painter.drawText(QRect(620,H1_y+Height+13,50,20),"ms");


    painter.setPen(pen_Yello);
    painter.setBrush(QBrush(QColor(255,128,0),Qt::SolidPattern));

    QList<int>RR=hi.time.RR;

    int RR_len=RR.size();
    if(RR_len>10){
        //绘制直方图
        int max_RR=RR.at(0);
        int min_RR=RR.at(0);
        int sum=0;
        for(int i=0;i<RR_len;i++){
            sum+=RR.at(i);
            if(max_RR<RR.at(i)){
                max_RR=RR.at(i);
            }
            if(min_RR>RR.at(i)){
                min_RR=RR.at(i);
            }
        }
        int range=(max_RR-min_RR)/7;
        QList<int>Hist_Num;
        QList<int>Hist_X;
        for(int i=0;i<7;i++){
            Hist_Num.append(0);
            Hist_X.append(min_RR+(i+0.5)*range);
        }
        for(int i=0;i<RR_len;i++){
            if(RR.at(i)>=min_RR && RR.at(i)<min_RR+range){
                Hist_Num.replace(0,Hist_Num.at(0)+1);
            }else if(RR.at(i)>=min_RR+range && RR.at(i)<min_RR+2*range){
                Hist_Num.replace(1,Hist_Num.at(1)+1);
            }else if(RR.at(i)>=min_RR+2*range && RR.at(i)<min_RR+3*range){
                Hist_Num.replace(2,Hist_Num.at(2)+1);
            }else if(RR.at(i)>=min_RR+3*range && RR.at(i)<min_RR+4*range){
                Hist_Num.replace(3,Hist_Num.at(3)+1);
            }else if(RR.at(i)>=min_RR+4*range && RR.at(i)<min_RR+5*range){
                Hist_Num.replace(4,Hist_Num.at(4)+1);
            }else if(RR.at(i)>=min_RR+5*range && RR.at(i)<min_RR+6*range){
                Hist_Num.replace(5,Hist_Num.at(5)+1);
            }else if(RR.at(i)>=min_RR+6*range && RR.at(i)<=max_RR){
                Hist_Num.replace(6,Hist_Num.at(6)+1);
            }
        }
        int Num_max=Hist_Num.at(0);
        for(int i=0;i<7;i++){
            if(Num_max<Hist_Num.at(i)){
                Num_max=Hist_Num.at(i);
            }
        }

        int BarWidth=2;
        painter.setPen(pen_Yello);
        for(int i=0;i<7;i++){
            int x_v=H1_x+width-width*(1200-Hist_X.at(i))/800;
            painter.drawRect(QRect(QPoint(x_v-BarWidth/2,H1_y+Height),QPoint(x_v+BarWidth/2,H1_y+Height-Height/Num_max*Hist_Num.at(i))));
        }

        //绘制差值直方图
        QList<int>RR_Diff;
        QList<int>RR_Abs_Diff;
        for(int i=0;i<RR_len-1;i++){
            RR_Diff.append(RR.at(i+1)-RR.at(i));
            RR_Abs_Diff.append(qAbs(RR.at(i+1)-RR.at(i)));
        }
        int max_RR_Diff=RR_Diff.at(0);
        int min_RR_Diff=RR_Diff.at(0);
        for(int i=0;i<RR_len-1;i++){
            if(max_RR_Diff<RR_Diff.at(i)){
                max_RR_Diff=RR_Diff.at(i);
            }
            if(min_RR_Diff>RR_Diff.at(i)){
                min_RR_Diff=RR_Diff.at(i);
            }
        }
        int range_diff=(max_RR_Diff-min_RR_Diff)/7;
        QList<int>Hist_Diff_Num;
        QList<int>Hist_Diff_X;
        for(int i=0;i<7;i++){
            Hist_Diff_Num.append(0);
            Hist_Diff_X.append(min_RR_Diff+(i+0.5)*range_diff);
        }
        for(int i=0;i<RR_len-1;i++){
            if(RR_Diff.at(i)>=min_RR_Diff && RR_Diff.at(i)<min_RR_Diff+range_diff){
                Hist_Diff_Num.replace(0,Hist_Diff_Num.at(0)+1);
            }else if(RR_Diff.at(i)>=min_RR_Diff+range_diff && RR_Diff.at(i)<min_RR_Diff+2*range_diff){
                Hist_Diff_Num.replace(1,Hist_Diff_Num.at(1)+1);
            }else if(RR_Diff.at(i)>=min_RR_Diff+2*range_diff && RR_Diff.at(i)<min_RR_Diff+3*range_diff){
                Hist_Diff_Num.replace(2,Hist_Diff_Num.at(2)+1);
            }else if(RR_Diff.at(i)>=min_RR_Diff+3*range_diff && RR_Diff.at(i)<min_RR_Diff+4*range_diff){
                Hist_Diff_Num.replace(3,Hist_Diff_Num.at(3)+1);
            }else if(RR_Diff.at(i)>=min_RR_Diff+4*range_diff && RR_Diff.at(i)<min_RR_Diff+5*range_diff){
                Hist_Diff_Num.replace(4,Hist_Diff_Num.at(4)+1);
            }else if(RR_Diff.at(i)>=min_RR_Diff+5*range_diff && RR_Diff.at(i)<min_RR_Diff+6*range_diff){
                Hist_Diff_Num.replace(5,Hist_Diff_Num.at(5)+1);
            }else if(RR_Diff.at(i)>=min_RR_Diff+6*range_diff && RR_Diff.at(i)<=max_RR_Diff){
                Hist_Diff_Num.replace(6,Hist_Diff_Num.at(6)+1);
            }
        }
        int Num_max_Diff=Hist_Diff_Num.at(0);
        for(int i=0;i<7;i++){
            if(Num_max_Diff<Hist_Diff_Num.at(i)){
                Num_max_Diff=Hist_Diff_Num.at(i);
            }
        }

        for(int i=0;i<7;i++){
            int x_v=H2_x+width-width*(400-Hist_Diff_X.at(i))/600;
            painter.drawRect(QRect(QPoint(x_v-BarWidth/2,H2_y+Height),QPoint(x_v+BarWidth/2,H2_y+Height-Height/Num_max_Diff*Hist_Diff_Num.at(i))));
        }
        //绘制差值绝对值直方图

        int max_RR_Diff_Abs=RR_Abs_Diff.at(0);
        int min_RR_Diff_Abs=RR_Abs_Diff.at(0);
        for(int i=0;i<RR_len-1;i++){
            if(max_RR_Diff_Abs<RR_Abs_Diff.at(i)){
                max_RR_Diff_Abs=RR_Abs_Diff.at(i);
            }
            if(min_RR_Diff_Abs>RR_Abs_Diff.at(i)){
                min_RR_Diff_Abs=RR_Abs_Diff.at(i);
            }
        }
        int range_diff_abs=(max_RR_Diff_Abs-min_RR_Diff_Abs)/7;
        QList<int>Hist_Abs_Diff_Num;
        QList<int>Hist_Abs_Diff_X;
        for(int i=0;i<7;i++){
            Hist_Abs_Diff_Num.append(0);
            Hist_Abs_Diff_X.append(min_RR_Diff_Abs+(i+0.5)*range_diff_abs);
        }
        for(int i=0;i<RR_len-1;i++){
            if(RR_Abs_Diff.at(i)>=min_RR_Diff_Abs && RR_Abs_Diff.at(i)<min_RR_Diff_Abs+range_diff_abs){
                Hist_Abs_Diff_Num.replace(0,Hist_Abs_Diff_Num.at(0)+1);
            }else if(RR_Abs_Diff.at(i)>=min_RR_Diff_Abs+range_diff_abs && RR_Abs_Diff.at(i)<min_RR_Diff_Abs+2*range_diff_abs){
                Hist_Abs_Diff_Num.replace(1,Hist_Abs_Diff_Num.at(1)+1);
            }else if(RR_Abs_Diff.at(i)>=min_RR_Diff_Abs+2*range_diff_abs && RR_Abs_Diff.at(i)<min_RR_Diff_Abs+3*range_diff_abs){
                Hist_Abs_Diff_Num.replace(2,Hist_Abs_Diff_Num.at(2)+1);
            }else if(RR_Abs_Diff.at(i)>=min_RR_Diff_Abs+3*range_diff_abs && RR_Abs_Diff.at(i)<min_RR_Diff_Abs+4*range_diff_abs){
                Hist_Abs_Diff_Num.replace(3,Hist_Abs_Diff_Num.at(3)+1);
            }else if(RR_Abs_Diff.at(i)>=min_RR_Diff_Abs+4*range_diff_abs && RR_Abs_Diff.at(i)<min_RR_Diff_Abs+5*range_diff_abs){
                Hist_Abs_Diff_Num.replace(4,Hist_Abs_Diff_Num.at(4)+1);
            }else if(RR_Abs_Diff.at(i)>=min_RR_Diff_Abs+5*range_diff_abs && RR_Abs_Diff.at(i)<min_RR_Diff_Abs+6*range_diff_abs){
                Hist_Abs_Diff_Num.replace(5,Hist_Abs_Diff_Num.at(5)+1);
            }else if(RR_Abs_Diff.at(i)>=min_RR_Diff_Abs+6*range_diff_abs && RR_Abs_Diff.at(i)<=max_RR_Diff_Abs){
                Hist_Abs_Diff_Num.replace(6,Hist_Abs_Diff_Num.at(6)+1);
            }
        }
        int Num_max_Diff_abs=Hist_Abs_Diff_Num.at(0);
        for(int i=0;i<7;i++){
            if(Num_max_Diff_abs<Hist_Abs_Diff_Num.at(i)){
                Num_max_Diff_abs=Hist_Abs_Diff_Num.at(i);
            }
        }

        for(int i=0;i<7;i++){
            int x_v=H3_x+width-width*(300-Hist_Abs_Diff_X.at(i))/300;
            painter.drawRect(QRect(QPoint(x_v-BarWidth/2,H2_y+Height),QPoint(x_v+BarWidth/2,H3_y+Height-Height*Hist_Abs_Diff_Num.at(i)/Num_max_Diff_abs)));
        }

    }
    //绘制时域指标值
    painter.setPen(Pen_Gray);
    int indexWidth=60;
    int indexHeight=15;
    painter.setBrush(QBrush(QColor(255,255,255),Qt::SolidPattern));
    for(int i=0;i<2;i++){
        painter.drawRect(QRect(QPoint(130,340+i*20),QPoint(130+indexWidth,340+i*20+indexHeight)));
        painter.drawRect(QRect(QPoint(330,340+i*20),QPoint(330+indexWidth,340+i*20+indexHeight)));
        painter.drawRect(QRect(QPoint(500,340+i*20),QPoint(500+indexWidth,340+i*20+indexHeight)));
        painter.drawRect(QRect(QPoint(680,340+i*20),QPoint(680+indexWidth,340+i*20+indexHeight)));
    }
    painter.setFont(font5);
    painter.setPen(Pen_Black);
    painter.drawText(QRect(70,342,60,20),"RR间期均值");
    painter.drawText(QRect(15,362,120,20),"相邻RR间期差的均方根");
    painter.drawText(QRect(282,342,60,20),"变异系数");
    painter.drawText(QRect(218,362,120,20),"相邻RR间期差的标准差");
    painter.drawText(QRect(440,342,60,20),"间期标准值");
    painter.drawText(QRect(470,362,120,20),"NN50");
    painter.drawText(QRect(635,342,60,20),"间期极差");
    painter.drawText(QRect(640,362,120,20),"PNN50%");

    painter.drawText(QRect(135,343,indexWidth,indexHeight),QString::number(hi.time.RR_mean,'f',2));
    painter.drawText(QRect(135,363,indexWidth,indexHeight),QString::number(hi.time.RR_RMSSD,'f',2));
    painter.drawText(QRect(335,343,indexWidth,indexHeight),QString::number(hi.time.RR_CV,'f',2));
    painter.drawText(QRect(335,363,indexWidth,indexHeight),QString::number(hi.time.RR_SDNN,'f',2));
    painter.drawText(QRect(505,343,indexWidth,indexHeight),QString::number(hi.time.pNN50*100,'f',0));
    painter.drawText(QRect(505,363,indexWidth,indexHeight),QString::number(hi.time.pNN50*100,'f',2));
    painter.drawText(QRect(685,343,indexWidth,indexHeight),QString::number(hi.time.RR_DRR,'f',2));
    painter.drawText(QRect(685,363,indexWidth,indexHeight),QString::number(hi.time.pNN50*100,'f',2));
    painter.setPen(Pen_Gray);
    painter.drawRect(QRect(QPoint(0,400),QPoint(761,440)));
    painter.setPen(Pen_Black);
    painter.drawText(QRect(3,402,761,40),"时域分析：是指控制系统在一定的输入下，根据输出量的时域表达式，分析系统的稳定性、瞬态和稳态性能。\n时域分析的优势：时域分析提供了时间域与频率域的联合分布信息，清楚地描述了信号频率随时间变化的关系。由于时域分析是直接在时间域中对系统进行分析的方法，所以时域分析具有直观和准确的优点。");


    //频域分析
    painter.setPen(Pen_Gray);
    painter.setBrush(QBrush(QColor(220,220,220),Qt::SolidPattern));
    painter.drawRect(QRect(QPoint(0,445),QPoint(761,470)));
    painter.setPen(pen_Yello);
    painter.setFont(font2);
    painter.drawText(QRect(10,450,150,25),"△频域分析");


    painter.setPen(Pen_Gray);
    painter.setBrush(QBrush(QColor(255,255,255),Qt::SolidPattern));
    painter.drawRect(QRect(50,500,240,100));
    painter.setPen(Pen_Black);
    painter.drawText(QRect(145,475,150,25),"频谱图");
    QList<double>psd=hi.freq.psd;
    double max_psd=psd.at(0);
    for(int i=0;i<128;i++){
        if(max_psd<psd.at(i)){
            max_psd=psd.at(i);
        }
    }
    int segranger=max_psd/5;
    painter.setFont(font5);
    for(int i=0;i<6;i++){
        painter.drawLine(47,500+20*i,50,500+20*i);
        if(i<5){
            painter.drawText(QRect(0,500+20*i-5,50,25),QString::number(max_psd-i*segranger,'f',1));
        }else{
            painter.drawText(QRect(25,500+20*i-5,50,25),QString::number(0.0,'f',1));
        }
    }
    for(int i=0;i<3;i++){
        painter.drawLine(50+120*i,600,50+120*i,603);
        painter.drawText(QRect(50+120*i-10,605,20,20),QString::number(0.2*i,'f',1));
    }
    painter.drawText(QRect(155,615,100,20),"频率(hz)");

    QList<QPointF> points1; // 曲线一的顶点数组
    QPainterPath smoothCurvePath1; // 平滑曲线一
    // 生成曲线的坐标
    QList<double>freqcy=hi.freq.psd;
    double x1=50;
    double y1=0;
    for (int i = 0; i < 513; i++) {
        x1 += 240.0 / 513.0;
        y1 = 600-100*psd.at(i)/max_psd;
        points1 << QPointF(x1, y1);
    }
    // 使用曲线的坐标生成平滑曲线
    smoothCurvePath1 = SmoothCurveGenerator::generateSmoothCurve(points1); // 不封闭
    // 绘制平滑曲线和曲线上的顶点
    painter.setRenderHint(QPainter::Antialiasing);
    painter.setBrush(QBrush(QColor(255,255,255),Qt::SolidPattern));
    painter.setPen(QPen(QColor(255,128,0), 1));
    painter.drawPath(smoothCurvePath1);

    painter.setPen(Pen_Gray);
    indexWidth=80;//重新定义指标宽度

    for(int i=0;i<4;i++){
        painter.drawRect(QRect(330+i*100,520,indexWidth,indexHeight));
    }
    for(int i=0;i<3;i++){
        painter.drawRect(QRect(330+i*100,570,indexWidth,indexHeight));
    }

    painter.setPen(Pen_Black);
    painter.drawText(QRect(330,505,indexWidth,indexHeight),"TP");
    painter.drawText(QRect(430,505,indexWidth,indexHeight),"VLF");
    painter.drawText(QRect(530,505,indexWidth,indexHeight),"LF");
    painter.drawText(QRect(630,505,indexWidth,indexHeight),"HF");

    painter.drawText(QRect(330,555,indexWidth,indexHeight),"LF/HF");
    painter.drawText(QRect(430,555,indexWidth,indexHeight),"LFNorm");
    painter.drawText(QRect(530,555,indexWidth,indexHeight),"HFNorm");

    painter.drawText(QRect(333,523,indexWidth,indexHeight),QString::number(hi.freq.TP,'f',1));
    painter.drawText(QRect(433,523,indexWidth,indexHeight),QString::number(hi.freq.VLF,'f',1));
    painter.drawText(QRect(533,523,indexWidth,indexHeight),QString::number(hi.freq.LF,'f',1));
    painter.drawText(QRect(633,523,indexWidth,indexHeight),QString::number(hi.freq.HF,'f',1));
    painter.drawText(QRect(333,573,indexWidth,indexHeight),QString::number(hi.freq.LFHF,'f',1));
    painter.drawText(QRect(433,573,indexWidth,indexHeight),QString::number(hi.freq.LFnorm,'f',1));
    painter.drawText(QRect(533,573,indexWidth,indexHeight),QString::number(hi.freq.HFnorm,'f',1));


    painter.setPen(Pen_Gray);
    painter.drawRect(QRect(QPoint(0,630),QPoint(761,670)));
    painter.setPen(Pen_Black);
    painter.drawText(QRect(3,632,761,40),"频域分析：是指在对函数或信号进行分析时，分析其和频率有关部分，和时域分析相对。\n频域分析的优势：频域分析的表示法包含各个频率的相位，利用大小及相应的咨询可以将各频率的弦波给予不同的大小及相位，相加以后可以还原成原始的信号，广泛应用于某些非线性系统。");



    //非线性分析
    painter.setPen(Pen_Gray);
    painter.setBrush(QBrush(QColor(220,220,220),Qt::SolidPattern));
    painter.drawRect(QRect(QPoint(0,675),QPoint(761,700)));
    painter.setPen(pen_Yello);
    painter.setFont(font2);
    painter.drawText(QRect(10,680,150,25),"△非线性分析");


    painter.setPen(Pen_Black);
    painter.setBrush(QBrush(QColor(255,255,255),Qt::SolidPattern));
    painter.drawText(QRect(110,705,50,20),"散点图");
    painter.drawText(QRect(360,705,80,20),"散点差值图");

    painter.setPen(Pen_Gray);
    painter.drawRect(QRect(60,730,160,160));
    painter.drawRect(QRect(320,730,160,160));
    painter.setPen(Pen_Black);
    painter.setFont(font5);
    for(int i=0;i<5;i++){
        painter.drawLine(57,730+i*40,60,730+i*40);
        if(i>1){
            painter.drawText(QRect(35,730+i*40-5,30,20),QString::number(1200-i*200,'f',0));
        }else{
            painter.drawText(QRect(30,730+i*40-5,30,20),QString::number(1200-i*200,'f',0));
        }

        painter.drawLine(60+i*40,890,60+i*40,893);
        painter.drawText(QRect(60+i*40-10,893,30,20),QString::number(400+i*200,'f',0));
    }
    painter.drawText(QRect(120,905,50,20),"RRn(ms)");
    painter.drawText(QRect(0,800,50,20),"RRn+1");
    painter.drawText(QRect(3,810,50,20),"(ms)");

    for(int i=0;i<5;i++){
        painter.drawLine(317,730+i*40,320,730+i*40);
        if(i<2){
            painter.drawText(QRect(315+i*40-10,893,30,20),QString::number(-320+i*160,'f',0));
            painter.drawText(QRect(295,730+i*40-5,30,20),QString::number(320-i*160,'f',0));
        }else if(i==2){
            painter.drawText(QRect(326+i*40-10,893,30,20),QString::number(-320+i*160,'f',0));
            painter.drawText(QRect(305,730+i*40-5,30,20),QString::number(320-i*160,'f',0));
        }else{
            painter.drawText(QRect(320+i*40-10,893,30,20),QString::number(-320+i*160,'f',0));
            painter.drawText(QRect(290,730+i*40-5,30,20),QString::number(320-i*160,'f',0));
        }
        painter.drawLine(320+i*40,890,320+i*40,893);

    }
    painter.drawText(QRect(365,905,50,20),"RRn(ms)");
    painter.drawText(QRect(270,800,50,20),"RRn+1");
    painter.drawText(QRect(273,810,50,20),"(ms)");
    painter.setPen(Pen_Gray);
    painter.drawLine(60,890,220,730);
    painter.drawLine(320,890,480,730);

    painter.setPen(pen_Yello);
    painter.setBrush(QBrush(QColor(255,128,0),Qt::SolidPattern));
    for(int i=0;i<RR_len-1;i++){
        painter.drawEllipse(60+(RR.at(i)-400)/5-2, 730-(RR.at(i+1)-1200)/5-2, 4, 4);
    }

    QList<int>RR_Diff;
    for(int i=0;i<RR_len-1;i++){
        RR_Diff.append(RR.at(i+1)-RR.at(i));
    }
    for(int i=0;i<RR_len-2;i++){
        painter.drawEllipse(320+(RR_Diff.at(i)+300)/4-2, 730-(RR_Diff.at(i+1)-400)/4-2, 4, 4);
    }
    painter.setPen(Pen_Gray);
    painter.setBrush(QBrush(QColor(255,255,255),Qt::SolidPattern));
    for(int i=0;i<2;i++){
        painter.drawRect(QRect(530+i*100,760,indexWidth,indexHeight));
    }
    for(int i=0;i<2;i++){
        painter.drawRect(QRect(530+i*100,810,indexWidth,indexHeight));
    }
    painter.setPen(Pen_Black);
    painter.drawText(QRect(530,740,100,indexHeight),"向量角度指数VAI");
    painter.drawText(QRect(630,740,100,indexHeight),"向量长度指数VLI");
    painter.drawText(QRect(530,790,100,indexHeight),"短轴SD1");
    painter.drawText(QRect(630,790,100,indexHeight),"长轴SD2");

//    painter.drawText(QRect(533,763,indexWidth,indexHeight),QString::number(dataBean.NonLinearINdexs.at(0),'f',1));
//    painter.drawText(QRect(633,763,indexWidth,indexHeight),QString::number(dataBean.NonLinearINdexs.at(1),'f',1));
//    painter.drawText(QRect(533,813,indexWidth,indexHeight),QString::number(dataBean.NonLinearINdexs.at(2),'f',1));
//    painter.drawText(QRect(633,813,indexWidth,indexHeight),QString::number(dataBean.NonLinearINdexs.at(3),'f',1));


    painter.setPen(Pen_Gray);
    painter.drawRect(QRect(QPoint(0,920),QPoint(761,950)));
    painter.setPen(Pen_Black);
    painter.drawText(QRect(3,922,761,30),"非线性分析：是指不按比例、不成直线的关系，代表不规则的运动和突变。\n非线性分析的优势：非线性分析更加接近客观事物性质本身，是量化研究认识复杂知识的重要方法之一。");



    //结论
    painter.setPen(Pen_Gray);
    painter.setBrush(QBrush(QColor(220,220,220),Qt::SolidPattern));
    painter.drawRect(QRect(QPoint(0,950),QPoint(761,975)));
    painter.setPen(pen_Yello);
    painter.setFont(font2);
    painter.drawText(QRect(10,955,150,25),"△诊断结论");

    painter.setPen(Pen_Gray);
    painter.setFont(font4);
    painter.setBrush(QBrush(QColor(255,255,255),Qt::SolidPattern));
    painter.drawRect(QRect(0,980,761,80));
    painter.setPen(Pen_Black);
    painter.drawText(QRect(3,983,761,80),hi.MentalPressureResults);
    painter.drawText(QRect(500,1065,300,20),"本报告仅供参考，不作为医疗依据");

}

void PrintReport::Report_HRV_Professional(DataBeans dataBean)
{
//    QString PatientID=dataBean.UserID;
    QSettings *setting=new QSettings("./Configuration.ini",QSettings::IniFormat);
    setting->beginGroup("Config");
    QString JGName=setting->value("User").toString();
    setting->endGroup();
    delete setting;
    QString Age=dataBean.UserAge;
    QString Gender=dataBean.UserSex;
    QString MeasureTime=dataBean.MeasureTime;
    QString UserName=dataBean.UserName;
    HRVDataProcess hrvdataPro;
    HRVIndex hi=hrvdataPro.Json2HRVData(dataBean.hrvIndexResults);
    QPrinter printer;
    printer.setPageSize(QPageSize::A4);
    printer.setResolution(100);
    printer.setPageMargins(QMarginsF(5,0,0,0));
//    printer.setOutputFormat(QPrinter::PdfFormat);
//    printer.setOutputFileName("C:\\Users\\whb\\Desktop\\report_HRV.pdf");
    if(Constant::PrintType=="输出pdf"){
        QString ParentFolder="D:\\data\\"+dataBean.UserID;
        QDir dir(ParentFolder);
        QString fileName;
        if(dir.exists())
        {
            fileName=ParentFolder+"\\"+dataBean.MeasureTime.replace(":","")+".pdf";
        }else
        {
            bool ok = dir.mkpath(ParentFolder);//创建多级目录
            if(ok)
            {
                fileName=ParentFolder+"\\"+dataBean.MeasureTime.replace(":","")+".pdf";
            }
        }
        printer.setOutputFileName(fileName);
    }
    QPainter painter(&printer);
    painter.setRenderHint(QPainter::Antialiasing);
    //定义几种画笔
    QPen pen_White,pen_Yello,Pen_Gray,Pen_Black,Pen_Red,Pen_Blue,Pen_Ranger,Pen_Grren,Pen_his;
    pen_White.setWidth(1);
    pen_Yello.setWidth(1);
    Pen_Gray.setWidth(1);
    Pen_Black.setWidth(1);
    Pen_Red.setWidth(1);
    Pen_Blue.setWidth(1);
    Pen_Ranger.setWidth(1);
    Pen_Grren.setWidth(1);
    Pen_his.setWidth(1);
    pen_White.setColor(QColor(255,255,255));
    pen_Yello.setColor(QColor(255,128,0));
    Pen_Gray.setColor(QColor(220,220,220));
    Pen_Black.setColor(QColor(0,0,0));
    Pen_Red.setColor(QColor(255,0,0));
    Pen_Blue.setColor(QColor(0,0,255));
    Pen_Ranger.setColor(QColor(175,152,181));
    Pen_Grren.setColor(QColor(0,225,0));
    Pen_his.setColor(QColor(107,100,144));
    painter.setPen(pen_White);
    //定义几种字体
    QFont font1("宋体",20,false);
    QFont font2("隶书",12,false);
    QFont font3("宋体",15,false);
    QFont font4("宋体",10,false);
    QFont font5("宋体",8,false);
    painter.setFont(font1);
    //--------------------------------------------绘制标题边框-------------------------------------------
    painter.setPen(Pen_Gray);
    painter.setBrush(QBrush(QColor(255,255,255),Qt::SolidPattern));
    painter.drawRect(QRect(0,80,770,1080));
    painter.setPen(Pen_Black);
//    painter.drawText(QRect(250,20,500,50),"心率变异趋势图");
//    painter.drawText(QRect(195,10,1000,50),"亳州高新区社区卫生服务中心");
    painter.drawText(QRect(190,35,800,50),"精神压力分析(心率变异性)检测报告");
    //--------------------------------------------绘制测试信息-------------------------------------------
    painter.setFont(font2);
    painter.drawText(QRect(60,100,110,140),"姓名");
    painter.drawText(QRect(220,100,250,140),"性别");
    painter.drawText(QRect(360,100,390,140),"年龄");
    painter.drawText(QRect(480,100,540,140),"登记日期");

    painter.drawText(QRect(90+30,100,220,120),UserName);
    painter.drawText(QRect(250+40,100,360,120),Gender);
    painter.drawText(QRect(390+40,100,480,120),Age);
    painter.drawText(QRect(540+20,100,761,120),MeasureTime);

    painter.drawText(QRect(20,130,200,50),"检测结果");
    painter.drawText(QRect(360,130,640,50),"检测机构: "+JGName);
    painter.setPen(Pen_Gray);
    painter.drawRect(QRect(10,150,750,140));
    painter.setPen(Pen_Black);
    painter.drawText(QRect(20,155,300,50),"时间领域分析");
    painter.drawText(QRect(400,155,300,50),"频率领域分析");

    painter.setBrush(QBrush(QColor(230,230,230),Qt::SolidPattern));
    painter.drawRect(QRect(20,180,100,20));
    painter.drawRect(QRect(20,205,100,20));
    painter.drawRect(QRect(20,230,100,20));
    painter.drawRect(QRect(20,255,100,20));

    painter.drawRect(QRect(200,180,100,20));
    painter.drawRect(QRect(200,205,100,20));
    painter.drawRect(QRect(200,230,100,20));
    painter.drawRect(QRect(200,255,100,20));

    painter.drawRect(QRect(400,180,100,20));
    painter.drawRect(QRect(400,205,100,20));
    painter.drawRect(QRect(400,230,100,20));
    painter.drawRect(QRect(400,255,100,20));

    painter.drawRect(QRect(580,180,100,20));
    painter.drawRect(QRect(580,205,100,20));
    painter.drawRect(QRect(580,230,100,20));

    painter.setBrush(QBrush(QColor(255,255,255),Qt::SolidPattern));
    painter.drawRect(QRect(120,180,70,20));
    painter.drawRect(QRect(120,205,70,20));
    painter.drawRect(QRect(120,230,70,20));
    painter.drawRect(QRect(120,255,70,20));

    painter.drawRect(QRect(300,180,70,20));
    painter.drawRect(QRect(300,205,70,20));
    painter.drawRect(QRect(300,230,70,20));
    painter.drawRect(QRect(300,255,70,20));

    painter.drawRect(QRect(500,180,70,20));
    painter.drawRect(QRect(500,205,70,20));
    painter.drawRect(QRect(500,230,70,20));
    painter.drawRect(QRect(500,255,70,20));

    painter.drawRect(QRect(680,180,70,20));
    painter.drawRect(QRect(680,205,70,20));
    painter.drawRect(QRect(680,230,70,20));

    painter.setFont(font4);
    painter.drawText(QRect(25,180+2,100,20),"MeanHRT(bpm)");
    painter.drawText(QRect(25,205+2,100,20),"SDNN(ms)");
    painter.drawText(QRect(25,230+2,100,20),"RMSSD(ms)");
    painter.drawText(QRect(25,255+2,100,20),"PSI");

    painter.drawText(QRect(205,180+2,100,20),"SDSD(ms)");
    painter.drawText(QRect(205,205+2,100,20),"DRR(ms)");
    painter.drawText(QRect(205,230+2,100,20),"PNN50(%)");
    painter.drawText(QRect(205,255+2,100,20),"CV");

    painter.drawText(QRect(405,180+2,100,20),"TP(ms2)");
    painter.drawText(QRect(405,205+2,100,20),"VLF(ms2)");
    painter.drawText(QRect(405,230+2,100,20),"LF(ms2)");
    painter.drawText(QRect(405,255+2,100,20),"HF(ms2)");

    painter.drawText(QRect(585,180+2,100,20),"LFNorm(n.u.)");
    painter.drawText(QRect(585,205+2,100,20),"HFNorm(n.u.)");
    painter.drawText(QRect(585,230+2,100,20),"LF/HF");


    painter.drawText(QRect(120+5,180+2,70,20),QString::number(hi.sl.MeanHrt,'f',1));
    painter.drawText(QRect(120+5,205+2,70,20),QString::number(hi.time.RR_SDNN,'f',1));
    painter.drawText(QRect(120+5,230+2,70,20),QString::number(hi.time.RR_RMSSD,'f',1));
    painter.drawText(QRect(120+5,255+2,70,20),QString::number(hi.time.Psi,'f',1));

    painter.drawText(QRect(300+5,180+2,70,20),QString::number(hi.time.SDSD,'f',1));
    painter.drawText(QRect(300+5,205+2,70,20),QString::number(hi.time.RR_DRR,'f',1));
    painter.drawText(QRect(300+5,230+2,70,20),QString::number(hi.time.NN50,'f',1));
    painter.drawText(QRect(300+5,255+2,70,20),QString::number(hi.time.RR_CV,'f',1));

    painter.drawText(QRect(500+5,180+2,70,20),QString::number(hi.freq.TP,'f',1));
    painter.drawText(QRect(500+5,205+2,70,20),QString::number(hi.freq.VLF,'f',1));
    painter.drawText(QRect(500+5,230+2,70,20),QString::number(hi.freq.LF,'f',1));
    painter.drawText(QRect(500+5,255+2,70,20),QString::number(hi.freq.HF,'f',1));

    painter.drawText(QRect(680+5,180+2,70,20),QString::number(hi.freq.LFnorm,'f',1));
    painter.drawText(QRect(680+5,205+2,70,20),QString::number(hi.freq.HFnorm,'f',1));
    painter.drawText(QRect(680+5,230+2,70,20),QString::number(hi.freq.LFHF,'f',1));

    painter.setPen(Pen_Gray);
    painter.drawRect(QRect(10,300,750,625));
    painter.setPen(Pen_Black);
    painter.setFont(font2);
    painter.drawText(QRect(220,310,200,50),"心率变异波形图(bpm)");
    painter.drawText(QRect(630,310,200,50),"直方图");

    painter.setPen(Pen_Gray);
    painter.drawRect(QRect(50,335,480,150));
    painter.drawRect(QRect(580,335,150,150));

    painter.setPen(Pen_Black);
    for(int i=0;i<6;i++){
        painter.drawLine(48,335+i*30,50,335+i*30);
        if(i<3){
            painter.drawText(QRect(20,328+i*30,40,20),QString::number(140-i*20));
        }else{
            painter.drawText(QRect(28,328+i*30,40,20),QString::number(140-i*20));
        }

    }
    painter.setPen(pen_Yello);
    QList<int>RR=hi.time.RR;
    QList<QPointF> points1; // 曲线一的顶点数组
    QPainterPath smoothCurvePath1; // 平滑曲线一
    // 生成曲线的坐标
    double x11=50;
    double y11=0;
    double mean_hr=0;
    QList<double>hr;
    for (int i = 0; i < RR.size(); i++) {
        x11 += 480.0 / RR.size();
        double temp_hr=60000/RR.at(i);
        if(temp_hr>140)
            temp_hr=140;
        else if(temp_hr<40)
            temp_hr=40;
        y11 = -150*(temp_hr-140)/100+335;
        points1 << QPointF(x11, y11);
        mean_hr+=60000.0/RR.at(i);
        hr.append(60000.0/RR.at(i));
    }
    double sum;
    for(int i=0;i<hr.length();i++)
    {
        sum+=hr.at(i);
    }
    double ListMean= sum/hr.length();

    double temp_std=0;
    for(int i=0;i<hr.length();i++)
    {
        temp_std+=qPow(hr.at(i)-ListMean,2);
    }
    double std_hr=qSqrt(temp_std/hr.length()-1) ;;
    mean_hr=mean_hr/RR.size();
    if(std_hr>15){
        std_hr=15;
    }


    // 使用曲线的坐标生成平滑曲线
    smoothCurvePath1 = SmoothCurveGenerator::generateSmoothCurve(points1); // 不封闭
    // 绘制平滑曲线和曲线上的顶点
    painter.setRenderHint(QPainter::Antialiasing);
    painter.setBrush(QBrush(QColor(255,255,255),Qt::SolidPattern));
    painter.setPen(QPen(QColor(107,100,144), 1));
    painter.drawPath(smoothCurvePath1);
//        painter.setBrush(Qt::gray);
    for (int i = 0; i < points1.length() ; i += 1) {
        painter.drawEllipse(points1[i].x()-1, points1[i].y()-1, 2, 2);
    }
    painter.setPen(QPen(QBrush(QColor(255,128,0)),1,Qt::DotLine));
    painter.drawLine(50,-150*(mean_hr-140)/100+335,530,-150*(mean_hr-140)/100+335);
    painter.setPen(QPen(QBrush(Qt::red),1,Qt::DotLine));
    painter.drawLine(50,-150*(mean_hr+1*std_hr-140)/100+335,530,-150*(mean_hr+1*std_hr-140)/100+335);
    painter.drawLine(50,-150*(mean_hr-1*std_hr-140)/100+335,530,-150*(mean_hr-1*std_hr-140)/100+335);

    painter.setPen(Pen_his);
    painter.setBrush(QBrush(QColor(107,100,144),Qt::SolidPattern));

//    QList<int>RR=dataBean.RR;

    int RR_len=RR.size();
    if(RR_len>10){
        //绘制直方图
        int max_RR=RR.at(0);
        int min_RR=RR.at(0);
        int sum=0;
        for(int i=0;i<RR_len;i++){
            sum+=RR.at(i);
            if(max_RR<RR.at(i)){
                max_RR=RR.at(i);
            }
            if(min_RR>RR.at(i)){
                min_RR=RR.at(i);
            }
        }
        int range=(max_RR-min_RR)/7;
        QList<int>Hist_Num;
        QList<int>Hist_X;
        for(int i=0;i<7;i++){
            Hist_Num.append(0);
            Hist_X.append(min_RR+(i+0.5)*range);
        }
        for(int i=0;i<RR_len;i++){
            if(RR.at(i)>=min_RR && RR.at(i)<min_RR+range){
                Hist_Num.replace(0,Hist_Num.at(0)+1);
            }else if(RR.at(i)>=min_RR+range && RR.at(i)<min_RR+2*range){
                Hist_Num.replace(1,Hist_Num.at(1)+1);
            }else if(RR.at(i)>=min_RR+2*range && RR.at(i)<min_RR+3*range){
                Hist_Num.replace(2,Hist_Num.at(2)+1);
            }else if(RR.at(i)>=min_RR+3*range && RR.at(i)<min_RR+4*range){
                Hist_Num.replace(3,Hist_Num.at(3)+1);
            }else if(RR.at(i)>=min_RR+4*range && RR.at(i)<min_RR+5*range){
                Hist_Num.replace(4,Hist_Num.at(4)+1);
            }else if(RR.at(i)>=min_RR+5*range && RR.at(i)<min_RR+6*range){
                Hist_Num.replace(5,Hist_Num.at(5)+1);
            }else if(RR.at(i)>=min_RR+6*range && RR.at(i)<=max_RR){
                Hist_Num.replace(6,Hist_Num.at(6)+1);
            }
        }
        int Num_max=Hist_Num.at(0);
        for(int i=0;i<7;i++){
            if(Num_max<Hist_Num.at(i)){
                Num_max=Hist_Num.at(i);
            }
        }

        int H1_x=580;//直方图左上角x坐标
        int H1_y=335;//直方图左上角y坐标
        int width=150;//直方图宽度
        int Height=150;//直方图宽度
        int BarWidth=2;//直方图条形宽度
        painter.setPen(Pen_his);
        for(int i=0;i<7;i++){
            int x_v=H1_x+width-width*(1200-Hist_X.at(i))/800;
            painter.drawRect(QRect(QPoint(x_v-BarWidth/2,H1_y+Height),QPoint(x_v+BarWidth/2,H1_y+Height-Height/Num_max*Hist_Num.at(i))));
        }
    }

    painter.setPen(Pen_Gray);
    painter.setBrush(QBrush(QColor(255,255,255),Qt::SolidPattern));
    painter.drawRect(QRect(50,520,240,150));
    painter.setPen(Pen_Black);
    painter.drawText(QRect(125,500,150,25),"能量光谱密度图");
    QList<double>psd=hi.freq.psd;
    double max_psd=psd.at(0);
    for(int i=0;i<128;i++){
        if(max_psd<psd.at(i)){
            max_psd=psd.at(i);
        }
    }
    painter.setFont(font5);

    for(int i=0;i<3;i++){
        painter.drawLine(50+120*i,670,50+120*i,673);
        painter.drawText(QRect(50+120*i-10,675,20,20),QString::number(0.2*i,'f',1));
    }
    painter.drawText(QRect(155,685,100,20),"频率(hz)");

    QList<QPointF> points2,points3; // 曲线一的顶点数组
    QPainterPath smoothCurvePath2,smoothCurvePath3; // 平滑曲线一
    // 生成曲线的坐标
    x11=50;
    y11=0;
    for (int i = 0; i < 40; i++) {
        x11 += 240.0 / 128.0;
        y11 = 670-150*psd.at(i)/max_psd;
        points2 << QPointF(x11, y11);
    }
    points2 << QPointF(x11, 670);
    points2 << QPointF(50, 670);
    // 使用曲线的坐标生成平滑曲线
    smoothCurvePath2 = SmoothCurveGenerator::generateSmoothCurve(points2,true,0.01); // 封闭
    // 绘制平滑曲线和曲线上的顶点
    painter.setRenderHint(QPainter::Antialiasing);
    painter.setBrush(QBrush(QColor(255,128,0),Qt::SolidPattern));
    painter.setPen(QPen(QColor(255,128,0), 1));
    painter.drawPath(smoothCurvePath2);
    int temp=x11;
    for (int i = 40; i < 128; i++) {
        x11 += 240.0 / 128.0;
        y11 = 670-150*psd.at(i)/max_psd;
        points3 << QPointF(x11, y11);
    }
    points3 << QPointF(x11, 670);
    points3 << QPointF(temp+480.0/128.0, 670);
    // 使用曲线的坐标生成平滑曲线
    smoothCurvePath3 = SmoothCurveGenerator::generateSmoothCurve(points3,true,0.01); // 封闭
    // 绘制平滑曲线和曲线上的顶点
    painter.setRenderHint(QPainter::Antialiasing);
    painter.setBrush(QBrush(QColor(145,92,110),Qt::SolidPattern));
    painter.setPen(QPen(QColor(145,92,110), 1));
    painter.drawPath(smoothCurvePath3);

    //绘制交感神经和迷走神经系统柱状图
    painter.setBrush(QBrush(QColor(255,255,255),Qt::SolidPattern));
    painter.setPen(Pen_Gray);
    painter.drawRect(QRect(320,520,100,150));//交感神经和迷走神经系统柱状图表格
    painter.drawRect(QRect(450,520,280,150));//精神压力表格图

    painter.setPen(Pen_Black);
    painter.drawText(QRect(325,500,50,20),"迷走神经");
    painter.drawText(QRect(375,500,50,20),"交感神经");

    painter.setBrush(QBrush(QColor(255,0,0),Qt::SolidPattern));
    painter.setPen(Pen_Red);
    painter.drawRect(335,670-1.5*hi.freq.HFnorm,30,1.5*hi.freq.HFnorm);
    painter.setBrush(QBrush(QColor(0,0,255),Qt::SolidPattern));
    painter.setPen(Pen_Blue);
    painter.drawRect(375,670-1.5*hi.freq.LFnorm,30,1.5*hi.freq.LFnorm);

    painter.setPen(Qt::NoPen);
    QLinearGradient bgGradient(465, 550, 715, 575);
    bgGradient.setColorAt(0.0, QColor(47, 200, 0));
    bgGradient.setColorAt(0.5, QColor(255, 255, 120));
    bgGradient.setColorAt(1.0, QColor(200, 50, 20));
    painter.setBrush(bgGradient);
    painter.drawRect(QRect(465, 550, 250, 25));

    QLinearGradient bgGradient2(465, 610, 715, 635);
    bgGradient2.setColorAt(0.0, QColor(47, 30, 255));
    bgGradient2.setColorAt(0.5, QColor(47, 200, 0));
    bgGradient2.setColorAt(1.0, QColor(200, 50, 20));
    painter.setBrush(bgGradient2);
    painter.drawRect(QRect(465, 610, 250, 25));

    painter.setPen(Pen_Black);
    painter.setFont(font2);
    painter.drawText(QRect(565,500,100,20),"压力指数");
    painter.setFont(font5);
    painter.drawText(QRect(572,525,80,20),"压力状态");
    painter.drawText(QRect(465,578,30,20),"正常");
    painter.drawText(QRect(700,578,30,20),"大");
    painter.drawText(QRect(572,590,80,20),"情绪状态");
    painter.drawText(QRect(465,638,30,20),"低");
    painter.drawText(QRect(700,638,30,20),"高");

    painter.setPen(pen_White);
    painter.setBrush(QBrush(QColor(255,255,255),Qt::SolidPattern));
    painter.drawRect(463+2.5*hi.mp.TotalScore,550,4,25);
    painter.drawRect(463+25*hi.mp.EmotionScore/10,610,4,25);

    painter.setPen(Pen_Gray);
    painter.drawRect(50,750,180,150);
    painter.drawRect(260,750,150,150);
    painter.drawRect(440,750,150,150);
    painter.drawRect(620,750,110,150);
    painter.setPen(Pen_Black);
    painter.setFont(font2);
    painter.drawText(QRect(75,730,150,20),"TP   VLF   LF    HF");
    painter.drawText(QRect(260,730,200,20),"自主神经系统平衡图");
    painter.drawText(QRect(490,730,80,20),"散点图");
    painter.drawText(QRect(630,730,200,20),"SDNN  RMSSD");
    painter.setFont(font5);
    painter.drawText(QRect(248,810,10,30),"高\n频");
    painter.drawText(QRect(320,905,30,20),"低频");


    double tp=hi.freq.TP;
    double vlf=hi.freq.VLF;
    double lf=hi.freq.LF;
    double hf=hi.freq.HF;

    if(tp>4500){
        tp=4450;
    }
    if(vlf>4000){
        vlf=3800;
    }
    if(lf>4000){
        lf=3900;
    }
    if(hf>3880){

    }
    //y = 2E-09x3 - 2E-05x2 + 0.1015x - 3.0302
    //6E-09x3 - 5E-05x2 + 0.1419x + 1.9286
//    int TPHeight=(2*pow(10,-9)*pow(tp,3) - 2*pow(10,-5)*pow(tp,2) + 0.1015*tp -3.0302)/1.7;
//    int VLFHeight=(6*pow(10,-9)*pow(vlf,3) - 5*pow(10,-5)*pow(vlf,2) + 0.1419*vlf +1.9286)/1.7;
//    int LFHeight=6*pow(10,-9)*pow(lf,3) - 5*pow(10,-5)*pow(lf,2) + 0.1419*lf +1.9286;
//    int HFHeight=6*pow(10,-9)*pow(hf,3) - 5*pow(10,-5)*pow(hf,2) + 0.1419*hf +1.9286;
    int TPHeight=hi.mp.tpScore*1.5;
    int VLFHeight=hi.mp.lfScore*hi.freq.VLF/hi.freq.LF;
    if(VLFHeight>150)
        VLFHeight=150;
    int LFHeight=hi.mp.lfScore*1.5;
    int HFHeight=hi.mp.hfScore*1.5;
    painter.setBrush(QBrush(QColor(209,195,132),Qt::SolidPattern));
    painter.setPen(Pen_Gray);
    painter.drawRect(QRect(65,900-TPHeight,25,TPHeight));
    painter.setBrush(QBrush(QColor(82,88,112),Qt::SolidPattern));
    painter.drawRect(QRect(105,900-VLFHeight,25,VLFHeight));
    painter.drawRect(QRect(145,900-LFHeight,25,LFHeight));
    painter.drawRect(QRect(185,900-HFHeight,25,HFHeight));
    painter.setPen(Pen_Ranger);
    painter.drawLine(76,790,80,790);
    painter.drawLine(76,820,80,820);
    painter.drawLine(78,790,78,820);

    painter.drawLine(116,800,120,800);
    painter.drawLine(116,830,120,830);
    painter.drawLine(118,800,118,830);

    painter.drawLine(156,805,160,805);
    painter.drawLine(156,835,160,835);
    painter.drawLine(158,805,158,835);

    painter.drawLine(196,810,200,810);
    painter.drawLine(196,840,200,840);
    painter.drawLine(198,810,198,840);

    QPoint CenterPoint=QPoint(335,825);//中心坐标
    int r1=75;
    int r2=55;
    int r3=25;
    int r4=5;
    painter.setFont(font2);
    painter.setPen(Pen_Gray);
    // 坐标轴的四个点
    QPen pen_Ellipse;
    pen_Ellipse.setColor(QColor(230,243,255));
    painter.setBrush(QBrush(QColor(230,243,255),Qt::SolidPattern)); //设置画刷形式
    painter.setPen(pen_Ellipse);
    painter.drawEllipse(CenterPoint,r1,r1);

    pen_Ellipse.setColor(QColor(214,234,253));
    painter.setBrush(QBrush(QColor(214,234,253),Qt::SolidPattern)); //设置画刷形式
    painter.setPen(pen_Ellipse);
    painter.drawEllipse(CenterPoint,r2,r2);

    pen_Ellipse.setColor(QColor(181,212,243));
    painter.setBrush(QBrush(QColor(181,212,243),Qt::SolidPattern)); //设置画刷形式
    painter.setPen(pen_Ellipse);
    painter.drawEllipse(CenterPoint,r3,r3);

    pen_Ellipse.setColor(QColor(100,180,232));
    painter.setBrush(QBrush(QColor(100,180,232),Qt::SolidPattern)); //设置画刷形式
    painter.setPen(pen_Ellipse);
    painter.drawEllipse(CenterPoint,r4,r4);
    //假定LF的正常范围
    int x_LF=hi.freq.LFnorm*150/100+260;
    int y_HF=900-150*hi.freq.HFnorm/100;
    pen_Ellipse.setColor(QColor(255,0,0));
    painter.setPen(pen_Ellipse);
    painter.setBrush(QBrush(QColor(255,0,0),Qt::SolidPattern)); //设置画刷形式
    painter.drawEllipse(x_LF-5, y_HF-5, 10, 10);

    painter.setPen(Pen_Gray);
    painter.drawLine(440,900,590,750);
    painter.setPen(Pen_Grren);
    painter.setBrush(QBrush(QColor(0,220,0),Qt::SolidPattern));
    for(int i=0;i<RR_len-1;i++){
        painter.drawEllipse(440+(RR.at(i)-400)/5.3333-1, 750-(RR.at(i+1)-1200)/5.3333-1, 2, 2);
    }


    painter.setPen(Pen_Gray);
    painter.setBrush(QBrush(QColor(82,88,112),Qt::SolidPattern));

    double SDNN=hi.time.RR_SDNN;
    double RMSSD=hi.time.RR_RMSSD;
//    y = 0.0005x3 - 0.0962x2 + 6.3606x - 3.7526

    if(SDNN>150){
        SDNN=150;
    }
    if(RMSSD>150){
        RMSSD=150;
    }
    int SDNNHeight=0.0005*pow(SDNN,3) - 0.0962*pow(SDNN,2) + 6.3606*SDNN - 3.7526;
    int RMSSDHeight=0.0005*pow(RMSSD,3) - 0.0962*pow(RMSSD,2) + 6.3606*RMSSD - 3.7526;


    painter.drawRect(QRect(635,900-SDNNHeight,25,SDNNHeight));
    painter.drawRect(QRect(685,900-RMSSDHeight,25,RMSSDHeight));


    painter.setPen(Pen_Gray);
    painter.setBrush(QBrush(QColor(255,255,255),Qt::SolidPattern));
    painter.drawRect(10,930,750,220);
    painter.setFont(font5);
    painter.setPen(Pen_Black);
    painter.drawText(QRect(12,932,746,220),hi.HRVResults+"\n"+hi.MentalPressureResults);
    painter.drawText(QRect(450,1120,300,20),"本报告仅供参考，不作为医疗诊断依据");
    painter.drawText(QRect(50,1120,300,20),"医师签字：");

}

void PrintReport::Report_APPG_Professional(DataBeans dataBean)
{
    QString PatientID=dataBean.UserID;
    QString Age=dataBean.UserAge;
    QString Gender=dataBean.UserSex;
    QString MeasureTime=dataBean.MeasureTime;
    QString UserName=dataBean.UserName;

    QPrinter printer;
    HRVDataProcess hrvdataPro;
    HRVIndex hi=hrvdataPro.Json2HRVData(dataBean.hrvIndexResults);
    printer.setPageSize(QPageSize::A4);
    printer.setResolution(100);
    printer.setPageMargins(QMarginsF(6,0,0,0));
//    printer.setOutputFormat(QPrinter::PdfFormat);
//    printer.setOutputFileName("C:\\Users\\whb\\Desktop\\report_ACC.pdf");

    if(Constant::PrintType=="输出pdf"){
        QString ParentFolder="D:\\data\\"+dataBean.UserID;
        QDir dir(ParentFolder);
        QString fileName;
        if(dir.exists())
        {
            fileName=ParentFolder+"\\"+dataBean.MeasureTime.replace(":","")+".pdf";
        }else
        {
            bool ok = dir.mkpath(ParentFolder);//创建多级目录
            if(ok)
            {
                fileName=ParentFolder+"\\"+dataBean.MeasureTime.replace(":","")+".pdf";
            }
        }
        printer.setOutputFileName(fileName);
    }
    QPainter painter(&printer);
    painter.setRenderHint(QPainter::Antialiasing);
    //定义几种画笔
    QPen pen_White,pen_Yello,Pen_Gray,Pen_Black,Pen_Red,Pen_Blue,Pen_Ranger,Pen_Grren,Pen_his;
    pen_White.setWidth(1);
    pen_Yello.setWidth(1);
    Pen_Gray.setWidth(1);
    Pen_Black.setWidth(1);
    Pen_Red.setWidth(1);
    Pen_Blue.setWidth(1);
    Pen_Ranger.setWidth(1);
    Pen_Grren.setWidth(1);
    Pen_his.setWidth(1);
    pen_White.setColor(QColor(255,255,255));
    pen_Yello.setColor(QColor(255,128,0));
    Pen_Gray.setColor(QColor(220,220,220));
    Pen_Black.setColor(QColor(0,0,0));
    Pen_Red.setColor(QColor(255,0,0));
    Pen_Blue.setColor(QColor(0,0,255));
    Pen_Ranger.setColor(QColor(175,152,181));
    Pen_Grren.setColor(QColor(0,225,0));
    Pen_his.setColor(QColor(107,100,144));
    painter.setPen(pen_White);
    //定义几种字体
    QFont font1("宋体",30,false);
    QFont font2("隶书",12,false);
    QFont font3("宋体",15,false);
    QFont font4("宋体",10,false);
    QFont font5("宋体",8,false);
    painter.setFont(font1);
    //--------------------------------------------绘制标题边框-------------------------------------------
    painter.setPen(Pen_Gray);
    painter.setBrush(QBrush(QColor(255,255,255),Qt::SolidPattern));
    painter.drawRect(QRect(0,80,770,1000));
    painter.setPen(Pen_Black);
    painter.drawText(QRect(200,20,500,50),"末梢血液循环检查报告");
    //--------------------------------------------绘制测试信息-------------------------------------------
    painter.setFont(font2);
    painter.drawText(QRect(60,100,110,140),"姓名");
    painter.drawText(QRect(220,100,250,140),"性别");
    painter.drawText(QRect(360,100,390,140),"年龄");
    painter.drawText(QRect(480,100,540,140),"登记日期");

    painter.drawText(QRect(90+30,100,220,120),UserName);
    painter.drawText(QRect(250+40,100,360,120),Gender);
    painter.drawText(QRect(390+40,100,480,120),Age);
    painter.drawText(QRect(540+20,100,761,120),MeasureTime);

    painter.setPen(Pen_Gray);
    painter.setBrush(QBrush(QColor(220,220,220),Qt::SolidPattern));
    painter.drawRect(QRect(10,130,200,30));
    painter.setPen(Pen_Black);
    painter.drawText(QRect(20,138,200,20),"△ 末梢血液循环检查");
    painter.setPen(Pen_Gray);
    painter.setBrush(QBrush(QColor(255,255,255),Qt::SolidPattern));
    painter.drawRect(QRect(10,165,745,50));
    painter.setPen(Pen_Black);
    painter.setFont(font4);
    painter.drawText(QRect(12,185,740,20),"采集手指端光电容积脉搏波信号，对其进行信号处理，得到末梢血液循环状态和血管老化程度结果。");


//    QList<double>ppg=dataBean.PPG;
//    getAppg getappg;
//    PPGAPPG ppgAppg=getappg.computePrensentPPG_APPG(ppg);
//    AcceleratedIndex accindex=getappg.computeAccIndex(ppgAppg);
    QList<double>presentPPG=hi.appg.Pre_PPG;
    QList<double>presentAPPG=hi.appg.Pre_APPG;
    int validLen=presentAPPG.size();

    painter.setPen(Pen_Gray);
    painter.setBrush(QBrush(QColor(220,220,220),Qt::SolidPattern));
    painter.drawRect(QRect(10,220,200,30));
    painter.setPen(Pen_Black);
    painter.drawText(QRect(20,228,200,20),"△ 波形分析结果");
    painter.setPen(Pen_Gray);
    painter.setBrush(QBrush(QColor(255,255,255),Qt::SolidPattern));
    painter.drawRect(QRect(10,275,360,200));
    painter.drawRect(QRect(400,275,360,200));
    painter.setPen(Pen_Black);
    painter.setFont(font4);
    painter.drawText(QRect(150,255,250,20),"脉搏波波形");
    painter.drawText(QRect(530,255,250,20),"加速度脉搏波波形");
    double max_psd=presentPPG.at(0);
    double min_psd=presentPPG.at(0);
    int len=presentPPG.size();
    for(int i=0;i<len;i++){
        if(max_psd<presentPPG.at(i)){
            max_psd=presentPPG.at(i);
        }
        if(min_psd>presentPPG.at(i)){
            min_psd=presentPPG.at(i);
        }
    }

    max_psd=max_psd*1.1;
//    min_psd=min_psd*0.9;
    QList<QPointF> points; // 曲线一的顶点数组
    QPainterPath smoothCurvePath; // 平滑曲线一
    // 生成曲线的坐标
    double x11=10;
    double y11=0;
    for (int i = 0; i < len; i++) {
        x11 += 360.0 / len;
        y11 = 275+200*(max_psd-presentPPG.at(i))/(max_psd-min_psd);
        points << QPointF(x11, y11);
    }

    // 使用曲线的坐标生成平滑曲线
    smoothCurvePath = SmoothCurveGenerator::generateSmoothCurve(points); // 封闭
    // 绘制平滑曲线和曲线上的顶点
    painter.setRenderHint(QPainter::Antialiasing);
    painter.setBrush(QBrush(QColor(255,255,255),Qt::SolidPattern));
    painter.setPen(QPen(QColor(0,100,200), 1));
    painter.drawPath(smoothCurvePath);

    //绘制加速度脉搏波
    max_psd=presentAPPG.at(0);
    min_psd=presentAPPG.at(0);
    len=presentAPPG.size();
    for(int i=0;i<len;i++){
        if(max_psd<presentAPPG.at(i)){
            max_psd=presentAPPG.at(i);
        }
        if(min_psd>presentAPPG.at(i)){
            min_psd=presentAPPG.at(i);
        }
    }

    max_psd=max_psd*1.1;
//    min_psd=min_psd*0.9;
    QList<QPointF> points2; // 曲线一的顶点数组
    QPainterPath smoothCurvePath2; // 平滑曲线一
    // 生成曲线的坐标
    x11=400;
    y11=0;
    for (int i = 0; i < len; i++) {
        x11 += 360.0 / len;
        y11 = 275+200*(max_psd-presentAPPG.at(i))/(max_psd-min_psd);
        points2 << QPointF(x11, y11);
    }

    // 使用曲线的坐标生成平滑曲线
    smoothCurvePath2 = SmoothCurveGenerator::generateSmoothCurve(points2); // 封闭
    // 绘制平滑曲线和曲线上的顶点
    painter.setRenderHint(QPainter::Antialiasing);
    painter.setBrush(QBrush(QColor(255,255,255),Qt::SolidPattern));
    painter.setPen(QPen(QColor(0,100,200), 1));
    painter.drawPath(smoothCurvePath2);

    painter.setPen(QPen(QBrush(Qt::black),1,Qt::DotLine));
    painter.drawLine(400,275+200*(max_psd)/(max_psd-min_psd),750,275+200*(max_psd)/(max_psd-min_psd));

    painter.setPen(Pen_Red);
    painter.setFont(font5);
    QList<QString>name;
    name.append("a");
    name.append("b");
    name.append("c");
    name.append("d");
    name.append("e");
    painter.setPen(QPen(QBrush(Qt::red),1,Qt::DotLine));
    for(int i=0;i<5;i++){
        int x_pos=400+360.0*hi.appg.abcde.at(i)/len;
        painter.drawLine(x_pos,280,x_pos,470);
//        painter.drawText(QRect(x_pos+2,465,15,15),name.at(i));
    }
//    Pen_Black.setStyle(Qt::DotLine);
    painter.setPen((QPen(QBrush(Qt::black),1,Qt::SolidLine)));
    for(int i=0;i<5;i++){
        int x_pos=400+360.0*hi.appg.abcde.at(i)/len;
        painter.drawText(QRect(x_pos+2,465,15,15),name.at(i));
    }

    painter.setPen(Pen_Gray);
    painter.setBrush(QBrush(QColor(220,220,220),Qt::SolidPattern));
    painter.drawRect(QRect(10,480,200,30));
    painter.setPen(Pen_Black);
    Pen_Black.setStyle(Qt::SolidLine);
    painter.drawText(QRect(20,490,200,20),"△ 血管状态分析结果");
    painter.setPen(Pen_Gray);
    painter.setBrush(QBrush(QColor(255,255,255),Qt::SolidPattern));
    painter.drawRect(QRect(10,520,180,200));
    painter.setFont(font2);
    painter.setPen(Pen_Black);
    painter.drawText(QRect(30,540,100,20),"平均心率：");
    painter.drawText(QRect(30,640,100,20),"波   形：");
    painter.setPen(Pen_Gray);
    painter.drawRect(QRect(30,570,150,30));
    painter.drawRect(QRect(30,670,150,30));
    painter.setPen(Pen_Black);
    painter.setFont(font4);
    painter.drawText(QRect(145,678,50,20),"阶段");
    painter.drawText(QRect(100,578,50,20),QString::number(60000/hi.time.RR_mean,'f',1));
    painter.drawText(QRect(100,678,20,20),QString::number(hi.appg.VascularState));

    painter.setPen(Pen_Gray);
    painter.setBrush(QBrush(QColor(255,255,255),Qt::SolidPattern));
    painter.drawRect(QRect(200,520,300,200));
    painter.drawRect(QRect(510,520,245,200));
    painter.setPen(Pen_Black);
    painter.drawText(QRect(520,525,200,20),"血管阶段分析：");
    for(int i=0;i<7;i++){
        painter.drawText(QRect(520,25*i+550,30,20),QString::number(i+1)+":");
        painter.drawText(QRect(710,25*i+550,50,20),QString::number(hi.appg.SevenState.at(i)*100,'f',1)+"%");
    }
    painter.setPen(QPen(QColor(0,100,200), 1));
    painter.setBrush(QBrush(QColor(0,100,200),Qt::SolidPattern));
    for(int i=0;i<7;i++){
        painter.drawRect(QRect(550,555+25*i,150*hi.appg.SevenState.at(i),5));
    }
    painter.setPen(Pen_Black);

    max_psd=presentAPPG.at(0);
    min_psd=presentAPPG.at(0);
    len=presentAPPG.size();
    for(int i=0;i<len;i++){
        if(max_psd<presentAPPG.at(i)){
            max_psd=presentAPPG.at(i);
        }
        if(min_psd>presentAPPG.at(i)){
            min_psd=presentAPPG.at(i);
        }
    }

    max_psd=max_psd*1.1;
//    min_psd=min_psd*0.9;
    QList<QPointF> points3; // 曲线一的顶点数组
    QPainterPath smoothCurvePath3; // 平滑曲线一
    // 生成曲线的坐标
    x11=200;
    y11=0;
    for (int i = 0; i < validLen; i++) {
        x11 += 300.0 / validLen;
        y11 = 520+200*(max_psd-presentAPPG.at(i))/(max_psd-min_psd);
        points3 << QPointF(x11, y11);
    }

    // 使用曲线的坐标生成平滑曲线
    smoothCurvePath3 = SmoothCurveGenerator::generateSmoothCurve(points3); // 封闭
    // 绘制平滑曲线和曲线上的顶点
    painter.setRenderHint(QPainter::Antialiasing);
    painter.setBrush(QBrush(QColor(255,255,255),Qt::SolidPattern));
    painter.setPen(QPen(QColor(0,100,200), 1));
    painter.drawPath(smoothCurvePath3);
    painter.setPen(QPen(QBrush(Qt::black),1,Qt::DotLine));
    painter.drawLine(200,520+200*(max_psd-0)/(max_psd-min_psd),500,520+200*(max_psd-0)/(max_psd-min_psd));

    painter.setPen(QPen(QBrush(Qt::red),1,Qt::DotLine));
    x11=200+300.0/validLen*hi.appg.abcde.at(1);
    y11=520+200*(max_psd-presentAPPG.at(hi.appg.abcde.at(1)))/(max_psd-min_psd);
    int x12=200+300.0/validLen*hi.appg.abcde.at(3);
    int y12=520+200*(max_psd-presentAPPG.at(hi.appg.abcde.at(3)))/(max_psd-min_psd);
    painter.drawLine(x11,y11,x12,y12);

    painter.setPen(Pen_Gray);
    painter.setBrush(QBrush(QColor(220,220,220),Qt::SolidPattern));
    painter.drawRect(QRect(10,750,200,30));
    painter.setPen(Pen_Black);
    Pen_Black.setStyle(Qt::SolidLine);
    painter.drawText(QRect(20,760,200,20),"△ 测量指标分析");
    painter.setPen(Pen_Gray);
    painter.setBrush(QBrush(QColor(255,255,255),Qt::SolidPattern));
    painter.drawRect(QRect(10,790,750,200));
    painter.setPen(QPen(QBrush(Qt::gray),1,Qt::DotLine));
    for(int i=0;i<4;i++){
        painter.drawLine(10,40*(i+1)+790,760,40*(i+1)+790);
    }
    painter.drawLine(180,790,180,990);
    painter.drawLine(300,790,300,990);
    painter.drawLine(450,790,450,990);
    painter.drawLine(600,790,600,990);

    painter.setPen(Pen_Black);
    painter.drawText(QRect(80,805,30,20),"项目");
    painter.drawText(QRect(220,805,50,20),"检测值");
    painter.drawText(QRect(340,805,80,20),"正常以下");
    painter.drawText(QRect(510,805,30,20),"正常");
    painter.drawText(QRect(640,805,80,20),"正常以上");
    painter.drawText(QRect(20,845,150,20),"微分脉搏指数(DPI)");
    painter.drawText(QRect(20,885,100,20),"每搏输出量(SP)");
    painter.drawText(QRect(20,925,100,20),"血管弹性(BVT)");
    painter.drawText(QRect(20,965,100,20),"残血量(RBV)");

    painter.drawText(QRect(215,845,100,20),QString::number(hi.appg.DPI,'f',2));
    painter.drawText(QRect(215,885,100,20),QString::number(hi.appg.SP,'f',2));
    painter.drawText(QRect(215,925,100,20),QString::number(hi.appg.BVT,'f',2));
    painter.drawText(QRect(215,965,100,20),QString::number(hi.appg.RBV,'f',2));

    painter.setPen(QPen(QColor(0,100,200), 1));
    painter.setBrush(QBrush(QColor(0,100,200),Qt::SolidPattern));
    QList<double>range_DPI,range_SP,range_BVT,range_RBV;
    range_DPI.append(0);
    range_DPI.append(-20);
    range_DPI.append(-120);
    range_DPI.append(-150);

    range_SP.append(0);
    range_SP.append(-20);
    range_SP.append(-50);
    range_SP.append(-150);

    range_BVT.append(0);
    range_BVT.append(-2);
    range_BVT.append(-13);
    range_BVT.append(-50);

    range_RBV.append(-50);
    range_RBV.append(-30);
    range_RBV.append(-5);
    range_RBV.append(0);
    painter.drawRect(QRect(300,845,getIndexLen(range_DPI,hi.appg.DPI,false),10));
    painter.drawRect(QRect(300,885,getIndexLen(range_SP,hi.appg.SP,false),10));
    if(hi.appg.BVT>0){
       painter.drawRect(QRect(300,925,getIndexLen(range_BVT,-1*hi.appg.BVT,false),10));
    }else{
        painter.drawRect(QRect(300,925,getIndexLen(range_BVT,hi.appg.BVT,false),10));
    }

    painter.drawRect(QRect(300,965,getIndexLen(range_RBV,hi.appg.RBV,true),10));

    painter.setPen(Pen_Gray);
    painter.setBrush(QBrush(QColor(255,255,255),Qt::SolidPattern));
    painter.drawRect(QRect(10,1000,750,70));
    painter.setPen(Pen_Black);
    painter.drawText(QRect(12,1005,750,70),"测量结论：\n\n"+hi.appg.Vascular_res);
    painter.drawText(QRect(450,1120,300,20),"本报告仅供参考，不作为医疗诊断依据");
    painter.drawText(QRect(50,1120,300,20),"医师签字：");


}

int PrintReport::getIndexLen(QList<double>ranger, double indexv,bool flag){
    //flag=true,范围从小变大，否则是从大变小
    double a=ranger.at(0);
    double b=ranger.at(1);
    double c=ranger.at(2);
    double d=ranger.at(3);
    int len=0;
    if(flag){
        if(indexv<a)
            indexv=a;
        if(indexv>d)
            indexv=d;
        if(indexv>=a && indexv<b){
            len=150-150*(b-indexv)/(b-a);
        }else if(indexv>=b && indexv<c){
            len=300-150*(c-indexv)/(c-b);
        }else{
            len=450-150*(d-indexv)/(d-c);
        }

    }else{
        if(indexv>a)
            indexv=a;
        if(indexv<d)
            indexv=d;
        if(indexv<=a && indexv>b){
            len=150-150*(b-indexv)/(b-a);
        }else if(indexv<=b && indexv>c){
            len=300-150*(c-indexv)/(c-b);
        }else{
            len=450-150*(d-indexv)/(d-c);
        }
    }

    return len;

}



